本文共 2437 字,大约阅读时间需要 8 分钟。
//one-to-oneExt.define('Address', { extend: 'Ext.data.Model', fields: [ 'address', 'city', 'state', 'zipcode' ]});Ext.define('Employee', { extend: 'Ext.data.Model', fields: [{ name: 'addressId', reference: 'Address' }]});//one-to-manyExt.define('Department', { extend: 'Ext.data.Model', fields: [ { name: 'employeeId', reference: 'Employee' } ]});Ext.define('Division', { extend: 'Ext.data.Model', fields: [ { name: 'departmentId', reference: 'Department' } ]});//many-to-manyExt.define('Employee', { extend: 'Ext.data.Model', fields: [ { name: 'empId', type: 'int', convert: null }, { name: 'firstName', type: 'string' }, { name: 'lastName', type: 'string' } ], manyToMany: 'Project'});Ext.define('Project', { extend: 'Ext.data.Model', fields: [ 'name' ], manyToMany: 'Employee'});//storevar myStore = Ext.create('Ext.data.Store', { model: 'Employee', storeId: 'mystore', proxy: { type: 'rest', url: '/employee', reader: { type: 'json', rootProperty: 'data' } }, autoLoad: true, autoSync: true});//inline data storeExt.create('Ext.data.Store', { model: 'Employee', data: [ { firstName: 'Shiva', lastName: 'Kumar', gender: 'Male', fulltime: true, phoneNumber: '123-456-7890' }, { firstName: 'Vishwa', lastName: 'Anand', gender: 'Male', fulltime: true, phoneNumber: '123-456-7890' } ]});//access the storeExt.data.StoreManager.lookup('myStore');Ext.getStore('myStore');var myStore = this.getViewModel().getStore('myStore')//store in viewmodelExt.define('ToDo.view.toDoList.ToDoListModel', { extend: 'Ext.app.ViewModel', alias: 'viewmodel.todoList', stores: { todos: { fields: [ { name: 'id', type: 'string' }, { name: 'desc', type: 'string' }], autoLoad: true, sorters: [{ property: 'done', direction: 'ASC' }], proxy: { type: 'rest', url: 'tasks', reader: { type: 'json', }, writer: { type: 'json' } } } }});
转载地址:http://tocra.baihongyu.com/