I would like to set programmatically the model of my datasource. Something like:
var ds = new kendo.data.DataSource({ //... });
var mod = kendo.data.Model.define({
fields: data
});
ds.model = mod;
Is it possible? How? Thank you.
I would like to set programmatically the model of my datasource. Something like:
var ds = new kendo.data.DataSource({ //... });
var mod = kendo.data.Model.define({
fields: data
});
ds.model = mod;
Is it possible? How? Thank you.
当然,但是您必须在DataSource
字段中进行设置schema.model
(请参阅schema.model 参考)
如本页所示,您将拥有如下内容:
// 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
}
});