3

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.

4

1 回答 1

4

当然,但是您必须在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
    }
});
于 2012-11-27T08:59:07.417 回答