我的绑定对象具有setter,并且在更改网格单元格中的值时,不会调用setter。为什么呢?
function PresonDetails(_contactName, _contactTitle, _country, _companyName) {
Object.defineProperties(this, {
"ContactName": {
get: function () {
return this._contactName;
},
set: function (value) {
alert("New ContactName is :" + value)
this._contactName = value; //Setter is not get called when i change the value in grid.
},
enumerable: true,
configurable: true
},
"ContactTitle": {
get: function () {
return this._contactTitle;
},
set: function (value) {
this._contactTitle = value;
},
enumerable: true,
configurable: true
},
"Country": {
get: function () {
return this._country;
},
set: function (value) {
this._country = value;
},
enumerable: true,
configurable: true
},
"CompanyName": {
get: function () {
return this._companyName;
},
set: function (value) {
this._companyName = value;
},
enumerable: true,
configurable: true
}
});
this.ContactName = _contactName;
this.ContactTitle = _contactTitle;
this.Country = _country;
this.CompanyName = _companyName;
}
(function () {
var details = [];
details.push(new PresonDetails("ContactName1", "ContactTitle", "USA", "MICro"));
var $grid = $('#grid');
$grid.kendoGrid({
scrollable: true,
dataSource: details,
groupable: false,
sortable: false,
editable: true,
columns: [{
field: "ContactName",
title: "Contact Name",
width: 200
}, {
field: "ContactTitle",
title: "Contact Title",
width: 250
}, {
field: "CompanyName",
title: "Company Name"
}, {
field: "Country",
width: 150,
}]
});
})();
以下是demo
答案 0 :(得分:2)
你是对的,它不是叫而是这是正确的。
嗯,我的意思是当你绑定一个数组时(这就是你所定义的details
),Kendo UI将它转换为ObservableObject
- 实际上是DataSource
内部使用的ObservableArray
是ObservableObjects
的数组 - 但这并不意味着使用您的对象定义。它的作用是从您的数据创建ObservableObject
,但在内部使用他们自己的Model
。