Sunday, December 9, 2012
ExtJS 4–Data Framework–Models–Part 1
In this post, we will be defining a Model and then we will define model and then validations on that. The class to extend is “Ext.data.Model”.
Ext.define('Training.model.Person', {
extend:'Ext.data.Model',
fields:[
{
name:'firstname',
type:'string'
},
{
name:'lastname',
type:'string'
},
{
name:'dob',
type:'date',
dateFormat:'m-d-Y'
},
{
name:'single',
type:'boolean'
}
]
});
The above model defines 4 fields. As we can see we can define a field of type date. The dateFormat defines the input format which will be parsed when we set the value for firstname. We can create object using Ext.create('Training.model.Person') and supply a config object as shown below. To access individual properties, we use Ext.get('fieldname').
var newPerson = Ext.create('Training.model.Person',{
firstname:'John',
lastname:'Doe',
dob:'10-21-2001',
single:true
}) ;
console.log("First name: "+newPerson.get('firstname'));
console.log("Last name: "+newPerson.get('lastname'));
console.log("dob: "+newPerson.get('dob'));
console.log("single: "+newPerson.get('single'));
The demo can be found here
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment