我正在编写一个强类型的类以用作kendo.data.Model
。我遇到的问题是,当我尝试为其中一个属性分配值时,它会进入无限循环。
例如,如果我有
let model = new ControllerModel();
model.Serial = "test123";
public set Serial(value: string)
被递归调用,直到堆栈溢出为止。我不确定需要哪种语法来指示set
方法使用set
类的kendo.data.Model
方法。我可以使用某种关键字或技术吗?
打字稿代码。...
class ControllerModel extends kendo.data.Model.define({
id: "Id",
fields: {
Id: { //Primary key
editable: false,
type: "number"
},
Serial: {
nullable: false,
validation: { required: true },
type: "string"
}
//Several other fields...
}
}) {
public get Id(): number {
return Number.parseInt(super.get('Id'));
}
public set Id(value: number) {
super.set('Id', value);
}
public get Serial(): string {
return <string>super.get('Serial');
}
public set Serial(value: string) {
super.set('Serial', value);
}
//Several other gets and sets...
}
JavaScript ...
var ControllerModel = /** @class */ (function (_super) {
__extends(ControllerModel, _super);
function ControllerModel() {
return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(ControllerModel.prototype, "Id", {
get: function () {
return Number.parseInt(_super.prototype.get.call(this, 'Id'));
},
set: function (value) {
_super.prototype.set.call(this, 'Id', value);
},
enumerable: true,
configurable: true
});
Object.defineProperty(ControllerModel.prototype, "Serial", {
get: function () {
return _super.prototype.get.call(this, 'Serial');
},
set: function (value) {
_super.prototype.set.call(this, 'Serial', value);
},
enumerable: true,
configurable: true
});
return ControllerModel;
}(kendo.data.Model.define({
id: "Id",
fields: {
Id: {
editable: false,
type: "number"
},
Serial: {
nullable: false,
validation: { required: true },
type: "string"
}
}
})));