Question about MVVM and data binding in Kendo Mobile:
account.js
:define([], function () { return { userPhone: 111 }; });
index.html
:<p>Phone: <span id="test-span" data-bind="html: userPhone"></span>.</p>
home-view.js
:define(["kendo", "app/account"], function (kendo, account) { var viewModel = kendo.observable({ userPhone: account.userPhone }); return { show: function() { viewModel.set("userPhone", account.userPhone); // LINE A account.userPhone = "222"; // LINE B }, viewModel: viewModel } });
- Without LINE A and LINE B,
#test-span
displays (null) - With only LINE A,
#test-span
displays "111" - With only LINE B,
#test-span
displays (null)
- Without LINE A and LINE B,
I understand why #2 behaves the way it does. I just doesn't understand why #1 and #3 behave as they do. I thought the whole point of MVVM and data-bindings is that I could update account.userPhone
and have it update views globally without having to do viewModel.set
.
Assuming I have home-view2.js
, home-view3.js
, etc, how can I update all viewModels will changing just the account property?