2
0

nested-props.html 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title></title>
  5. <meta charset="utf-8">
  6. <script src="bind.js"></script>
  7. <script src="../../../dist/seed.js"></script>
  8. </head>
  9. <body>
  10. <div id="a">
  11. <h1>a.b.c : <span sd-text="a.b.c"></span></h1>
  12. <h2>a.c : <span sd-text="a.c"></span></h2>
  13. <h3>Computed property that concats the two: <span sd-text="d"></span></h3>
  14. <button class="one" sd-on="click:one">one</button>
  15. <button class="two" sd-on="click:two">two</button>
  16. <button class="three" sd-on="click:three">three</button>
  17. <form id="form"><input name="msg" sd-model="msg"></form>
  18. <p class="hidden">{{sum}}</p>
  19. <button class="four" sd-on="click:four">four</button>
  20. <button class="empty1" sd-on="click:setEmpty">empty a.b</button>
  21. <button class="empty2" sd-on="click:setEmpty2">empty a</button>
  22. </div>
  23. <script>
  24. Seed.config({debug: true})
  25. var data = { c: 555 }
  26. var Demo = Seed.extend({
  27. lazy: true,
  28. init: function () {
  29. this.msg = 'Yoyoyo'
  30. this.a = data
  31. },
  32. proto: {
  33. one: function () {
  34. this.a = {
  35. c: 1,
  36. b: {
  37. c: 'one'
  38. }
  39. }
  40. },
  41. two: function () {
  42. this.a.b = {
  43. c: 'two'
  44. }
  45. this.a.c = 2
  46. },
  47. three: function () {
  48. this.a.b.c = 'three'
  49. this.a.c = 3
  50. },
  51. d: {
  52. $get: function () {
  53. return this.msg + (this.a.b.c || '') + (this.a.c || '')
  54. }
  55. },
  56. hidden: {
  57. a: 1,
  58. b: 2
  59. },
  60. sum: {
  61. $get: function () {
  62. return this.hidden.a + this.hidden.b
  63. }
  64. },
  65. four: function () {
  66. this.hidden.a++
  67. },
  68. setEmpty: function () {
  69. this.a.b = {}
  70. },
  71. setEmpty2: function () {
  72. this.a = {}
  73. }
  74. }
  75. })
  76. var app = new Demo({ el: '#a' })
  77. </script>
  78. </body>
  79. </html>