标题说明了一切。如何从javascript中触发Kendo可观察的更改事件?
我有this kendo observable example设置,所以当第一个名字被改变时,姓氏会改变,以匹配它。然而,如果您在JavaScript中更改名称,该示例不起作用(请参阅单击注册按钮的代码)。
感谢您的帮助。
标题说明了一切。如何从javascript中触发Kendo可观察的更改事件?
我有this kendo observable example设置,所以当第一个名字被改变时,姓氏会改变,以匹配它。然而,如果您在JavaScript中更改名称,该示例不起作用(请参阅单击注册按钮的代码)。
感谢您的帮助。
inding到模型更改事件应该解决的事情,你
$(document).ready(function() {
var viewModel = kendo.observable({
firstName: "John",
lastName: "Doe",
genders: ["Male", "Female"],
gender: "Male",
agreed: false,
confirmed: false,
register: function(e) {
this.set("firstName", "bobbyyyyy!!!");
e.preventDefault();
this.set("confirmed", true);
},
startOver: function() {
this.set("confirmed", false);
this.set("agreed", false);
this.set("gender", "Male");
this.set("firstName", "John");
this.set("lastName", "Doe");
},
firstNameChangeEvent:function(e) {
switch(e.field){
case "firstName":
this.set("lastName", this.get("firstName"));
break;
}
}
});
viewModel.bind("change", viewModel.firstNameChangeEvent);
kendo.bind($("#example"), viewModel);
});
如果名字是从代码改变firstNameChangeEvent将不会被解雇。更好的方法:
viewModel.bind("change", function(e) {
if(e.field == "firstName") {
this.set("lastName", this.get("firstName"));
}
});
这也适用。 – RayLoveless
谢谢,我用这个。 – RayLoveless