我使用RPNiemeyer`s剑道淘汰赛库。 我有一个在它剑道模板剑道网格。 在模板中存在使用淘汰赛点击绑定这就要求改变视图模型的方法的按钮。 重现步骤:
- 在网格中单击按钮。
- 一种方法被称为改变视图模型的财产,并提醒新值。
- 再次单击该按钮。 该按钮不起作用了。
注意:如果删除改变视图模型的一切工作正常属性的线。
请解释这是为什么不工作,任何想法和解决方案,将不胜感激的原因。 谢谢!
HTML:
<div id="grid" data-bind="kendoGrid: { data: fruits, columns: [
{
field: 'name',
title: 'Fruit',
width: 50
},
{
template: '<button class=\'k-button\' data-bind=\'click: function() { changeFruit() }\' >Change Fruit Name</button>',
width: 30
}
],
scrollable: false, sortable: true, pageable: false }" style="height: 380px">
</div>
JavaScript的:
var ViewModel = function() {
this.fruit1 = {
color: ko.observable("green"),
name: ko.observable("apple"),
};
this.fruit2 = {
color: ko.observable("orange"),
name: ko.observable("orange"),
};
this.fruits = ko.observableArray([
this.fruit1,
this.fruit2
]);
this.changeFruit = function() {
// this line breaks the binding,
// when You change the property of the viewModel
// You cannot call this function any more
this.fruits()[0].name("Test");
alert(this.fruits()[0].name());
}
};
ko.applyBindings(new ViewModel());
http://jsfiddle.net/hXn7e/25/