1. 程式人生 > >Kendoui:新建一個model

Kendoui:新建一個model

<script>
var Product = kendo.data.Model.define( {
    id: "id", // the identifier is the "id" field (declared below)
    fields: {
        /* name of the field */ name: {
            type: "string", // the field is a string
            validation: { // validation rules
                required: true // the field is required
            },
            defaultValue: "<empty>" // default field value
        },

        /* name of the field */ price: {
            type: "number", // the field is a number
            validation: { // validation rules
                required: true, // the field is required
                min: 1 // the minimum value is 1
            },
            defaultValue: 99.99 // default field value
        },

        /* name of the field */ id: {
            editable: false, // this field is not editable
            nullable: true // a default value will not be assigned
        }
    }
});
var product = new Product();
console.log(product.get("price")); // outputs "99.99" which is the default value
</script>