標題說明了一切。如何從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