Jsfiddle:http://jsfiddle.net/HCQAd/
var Editor = function(v1){
var self = this;
self.load_editor = function(item){
item.prop = "Test4";
}
}
var sectionView = function(){
var self = this;
self.items = ko.observableArray();
self.load_items = function(){
setTimeout(function(){
var items = [{prop:'Test'}, {prop:'Test2'}, {prop:'Test3'}];
self.items(items);
}, 500);
};
self.edit_item = function(item)
{
if(self.editor == null)
{
self.editor = new Editor(self);
self.editor.load_editor(item);
}
}
ko.applyBindings(self, $('.items_container')[0]);
}
var v1 = new sectionView();
v1.load_items();
<div class="items_container">
<!-- ko foreach: items -->
<span data-bind="text: prop"></span>
<a href="javascript:void(0);" data-bind="click: $parent.edit_item">edit</a>
<br/>
<!-- /ko -->
</div>
单击编辑链接将加载编辑器并传递正在编辑的项目。当我将属性设置为新值时,它不会更新原始视图?如何在原始视图中进行更新?
答案 0 :(得分:0)
您应该使用observable而不是普通属性。
您的可观测样本: http://jsfiddle.net/HCQAd/1/
关于敲除可观察性和双向数据绑定的文章。 http://knockoutjs.com/documentation/observables.html