据目前所知:Store至少分为两类,一个是SimpleStore,另一个是JsonStore。
1,用在gridPanel中常使用SimpleStore
2,填充表单中的下拉菜单(combo),常用JsonStore。
(1)简单JsonStore
批注:当时静态数据时,fields可以是['id','name','sex'],
如果是通过url动态获取数据是,必须是fields:[{name:'id'},{name:'suit'},{name:'type'}]
(2)通过url获取数据
例如,
注:先后顺序不能颠倒。先JsonStore,后ComboBox。
(3)高级用法对比
1,用在gridPanel中常使用SimpleStore
2,填充表单中的下拉菜单(combo),常用JsonStore。
(1)简单JsonStore
vardata=[{'id':1,'name':'小王','sex':'男'},
@H_404_18@ {'id':2,'name':'小李',250); line-height:18px"> {'id':3,'name':'小兰','sex':'女'},250); line-height:18px"> ];
@H_404_18@
var store=newExt.data.JsonStore({
@H_404_18@ data:data,250); line-height:18px"> fields:['id','name','sex']
@H_404_18@ });
批注:当时静态数据时,fields可以是['id','name','sex'],
如果是通过url动态获取数据是,必须是fields:[{name:'id'},{name:'suit'},{name:'type'}]
(2)通过url获取数据
例如,
varstore_modellist2= fields:['model'],250); line-height:18px"> url:'api/fail.PHP',250); line-height:18px"> root:'data',250); line-height:18px"> baseParams:{action:'get_all_models'}
@H_404_18@ });
@H_404_18@ store_modellist2.load();
var combo_model2=newExt.form.ComboBox({
@H_404_18@ width:100,250); line-height:18px"> editable:false,250); line-height:18px"> triggerAction:'all',250); line-height:18px"> allowBlank: store:store_modellist2,250); line-height:18px"> displayField:'model',250); line-height:18px"> value:"\u8BF7\u9009\u62E9\u673A\u578B",250); line-height:18px"> allQuery:"",//开启此项后,选择机型时将不再在此获取机型数据
@H_404_18@ listeners:{
@H_404_18@ 'select':function(obj,data,index){
var modelName=obj.getValue();
if (modelName!=="\u8BF7\u9009\u62E9\u673A\u578B"){
@H_404_18@ refresh_fail_chart(modelName);
@H_404_18@ }
@H_404_18@ //,mode:'local'
@H_404_18@ });
注:先后顺序不能颠倒。先JsonStore,后ComboBox。
(3)高级用法对比
//用法一
varjsonStore= url:'api/fail_parts_bydepart.PHP',250); line-height:18px"> 'loadexception':function(e){
@H_404_18@ alert(e.toString());
@H_404_18@ },250); line-height:18px"> {name:'name'},250); line-height:18px"> {name:'flash'},250); line-height:18px"> {name:'percent'}
@H_404_18@ jsonStore.load({
@H_404_18@ params:{
@H_404_18@ 'level':level,250); line-height:18px"> 'department':paras.department,250); line-height:18px"> 'product':paras.product,250); line-height:18px"> 'target':is_one,250); line-height:18px"> 'suit':paras.suit,250); line-height:18px"> 'model':paras.model,250); line-height:18px"> 'part':paras.part,250); line-height:18px"> 'dateStr':dateStr
//用法二
var store={
@H_404_18@ 'department': url:'api/list_k.PHP?action=department',250); line-height:18px"> fields:['name']}),250); line-height:18px"> 'product': url:'api/list_k.PHP?action=product',250); line-height:18px"> fields:['name']})
@H_404_18@ };
@H_404_18@ store.product.baseParams={'department':encodeURIComponent(data.data.name)};
@H_404_18@ store.product.load();
@H_404_18@ detailStore.on('beforeload',function(){
@H_404_18@ detailStore.baseParams={
@H_404_18@ });
JS中encodeURIComponent函数用PHP解码 在JS中使用了encodeURIComponent对中文进行编码在PHP中使用iconv('UTF-8','gb2312',$q);就可以得到你需要的字串了