1、实现数据的双向绑定:
html部分:
<div data-bind="text:name"></div>
<input type="text" data-bind="value:name">
js部分:
function ViewModel(){
this.id = 88;
this.name = ko.observable("apple");
};
ko.applyBindings(new ViewModel());
id为单向绑定,name为双向绑定;
2、依赖绑定
function AppViewModel(){
this.firstName = ko.observable("Micheal");
this.lastName = ko.observable("jaskson");
this.fullName = ko.computed(function(){
return this.firstName()+ " " +this.lastName();
})
})