2012-11-27 43 views

回答

3

當然,但你必須把它架在DataSourceschema.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 
    } 
}); 
+0

好的,但做到這一點意味着我必須初始化一個新的kendo.data.DataSource ...每次我想改變它的模型?我目前正在使用這種技術,但我想知道是否有一種方法來重寫模型,而不重新初始化整個數據源。 –

+0

也許(我沒有試過這個),你可以直接通過'dataSource.reader.model'來改變它,就像這篇文章的最後一個主題所示:(Kendo UI動態模式)[http://www.kendoui.c​​om/論壇/ UI /網格/無模式數據和 - 動態schema.aspx]。 –

+1

實際上這個解決方案似乎並不奏效:數據格式不正確。 –

相關問題