nested-props.html 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title></title>
  5. <meta charset="utf-8">
  6. <script src="../dist/seed.js"></script>
  7. </head>
  8. <body>
  9. <h1>a.b.c : {{a.b.c}}</h1>
  10. <h2>a.c : {{a.c}}</h2>
  11. <h3>Computed property that concats the two: {{d}}</h3>
  12. <button sd-on="click:one">one</button>
  13. <button sd-on="click:two">two</button>
  14. <button sd-on="click:three">three</button>
  15. <script>
  16. Seed.config({debug: true})
  17. var data1 = {
  18. c: 0,
  19. b: {
  20. c: 'zero'
  21. }
  22. },
  23. data = {
  24. c: 1,
  25. b: {
  26. c: 'one'
  27. }
  28. }
  29. var Demo = Seed.ViewModel.extend({
  30. init: function () {
  31. this.msg = 'Yoyoyo'
  32. this.a = data1
  33. },
  34. props: {
  35. one: function () {
  36. this.a = data
  37. },
  38. two: function () {
  39. this.a.b = {
  40. c: 'two'
  41. }
  42. this.a.c = 2
  43. },
  44. three: function () {
  45. this.a.b.c = 'three'
  46. this.a.c = 3
  47. },
  48. d: {get: function (ctx) {
  49. return (ctx.vm.msg + this.a.b.c + this.a.c) || ''
  50. }}
  51. }
  52. })
  53. var app = new Demo({ el: document.body })
  54. </script>
  55. </body>
  56. </html>