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>
Clicking the edit link loads the editor and passes the item being edited. When I set the property to a new value, it doesn’t update the original view? How do I make it update in the original view?
You should use observables instead of plain properties.
Your sample with observables:
http://jsfiddle.net/HCQAd/1/
Article about knockout observables and 2-way data-binding.
http://knockoutjs.com/documentation/observables.html