我想以编程方式设置我的数据源模型。 类似的东西:
var ds = new kendo.data.DataSource({ //... });
var mod = kendo.data.Model.define({
fields: data
});
ds.model = mod;
有可能吗?怎么样? 谢谢。
答案 0 :(得分:4)
当然,但您必须在DataSource
字段schema.model
中进行设置(请参阅schema.model reference)
如本页所示,您将拥有以下内容:
// Definition of your model
var Product = kendo.data.Model.define({
id: "ProductID",
fields: {
ProductID: {
//this field will not be editable (default value is true)
editable: false,
// a defaultValue will not be assigned (default value is false)
nullable: true
},
ProductName: {
validation: { //set validation rules
required: true
}
},
UnitPrice: {
//data type of the field {Number|String|Boolean|Date} default is String
type: "number",
// used when new model is created
defaultValue: 42,
validation: {
required: true,
min: 1
}
}
}
});
// Map this model to your DataSource object
var dataSource = new kendo.data.DataSource({
schema: {
model: Product // Use the existing Product model
}
});