ExtJS Ext.data.proxy.Memory
//定义模型 Ext.define('User', { extend: 'Ext.data.Model', fields: [ {name: 'id', type: 'int'}, {name: 'name', type: 'string'}, {name: 'phone', type: 'string', mapping: 'phoneNumber'} ] }); //定义数据 var data = { users: [ { id: 1, name: 'Ed Spencer', phoneNumber: '555 1234' }, { id: 2, name: 'Abe Elias', phoneNumber: '666 1234' } ] }; //使用Ext.data.Store var store = Ext.create('Ext.data.Store', { autoLoad: true, model: 'User', data : data, proxy: { type: 'memory', reader: { type: 'json', root: 'users' } } }); store.each(function(result){ console.log(result); });
extjs的LocalStorage使用的是html5的LocalStorage的API
Ext.define('Search', { fields: ['id', 'query'], extend: 'Ext.data.Model', proxy: { type: 'localstorage', id : 'twitter-Searches' } }); var store = Ext.create("Ext.data.Store",{ model:"Search" }); store.load(); store.add({query:"sadsad"}); store.sync(); store.each(function(result){ console.log(result); });
extjs的sessionstorage在chrome浏览器下一个标签就是一个独立的文件
Ext.define('Search', { fields: ['query'], extend: 'Ext.data.Model', proxy: { type: 'sessionstorage', id : 'myOtherProxyKey' } }); var store = Ext.create("Ext.data.Store",{ model:"Search" }); store.load(); store.add({query:"sadsad"}); store.sync(); store.each(function(result){ console.log(result); });
extjs的ajax方式
Ext.define('User', { extend: 'Ext.data.Model', fields: ['id', 'name', 'email'] }); var store = Ext.create('Ext.data.Store', { model: 'User', proxy: { type: 'ajax', url : 'user.php' } }); store.load({ scope: this, callback: function(records, operation, success) { console.log(records); } });
php
$arr = array( "name" => "sads", "age" => 12 ); $data = json_encode($arr); echo $data;