Kendo UI DataSource功能强大,Kendo UI的网格或者其它组件可以根据模型自动生成符合要求的编辑控件。下面的代码是模式示例:
<script>
var dataSource = new kendo.data.DataSource({
schema: {
model: {
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: {
//set validation rules
validation: { 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 }
}
}
}
}
});
</script>
上面的示例中列出了模型的重要属性。
editable:缺省是true,可以编辑,如果某个字段不希望编辑,可以设置为false。
nullable:缺省为false,是否为空。
validation:合法性验证,包括required,min,max等。
type:数据类型,可以根据类型生成对应的编辑组件,可选的值包括number,string,boolean,date。
defaultValue:缺省值。
网友评论