加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ExtJS之Store

发布时间:2020-12-16 19:22:52 所属栏目:百科 来源:网络整理
导读:据目前所知:Store至少分为两类,一个是SimpleStore,另一个是JsonStore。 1,用在gridPanel中常使用SimpleStore Js代码 var store_stat= new Ext.data.SimpleStore({ fields:[ {name: 'date' ,mapping: 'date' } ,{name: 'model' ,mapping: 'model' } 'per'
据目前所知:Store至少分为两类,一个是SimpleStore,另一个是JsonStore。

1,用在gridPanel中常使用SimpleStore
Js代码
  1. varstore_stat=newExt.data.SimpleStore({
  2. fields:[
  3. {name:'date',mapping:'date'}
  4. ,{name:'model',mapping:'model'}
  5. 'per',mapping:'per'}
  6. ]
  7. });


2,填充表单中的下拉菜单(combo),常用JsonStore。
(1)简单JsonStore
vardata=[{'id':1,'name':'小王','sex':'男'},
  • {'id':2,'name':'小李',250); line-height:18px"> {'id':3,'name':'小兰','sex':'女'},250); line-height:18px"> ];
  • varstore=newExt.data.JsonStore({
  • data:data,250); line-height:18px"> fields:['id','name','sex']
  • });


  • 批注:当时静态数据时,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'}
  • });
  • store_modellist2.load();
  • varcombo_model2=newExt.form.ComboBox({
  • 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:"u8BF7u9009u62E9u673Au578B",250); line-height:18px"> allQuery:"",//开启此项后,选择机型时将不再在此获取机型数据
  • listeners:{
  • 'select':function(obj,data,index){
  • varmodelName=obj.getValue();
  • if(modelName!=="u8BF7u9009u62E9u673Au578B"){
  • refresh_fail_chart(modelName);
  • }
  • //,mode:'local'
  • });


  • 注:先后顺序不能颠倒。先JsonStore,后ComboBox。

    (3)高级用法对比
    //用法一
  • varjsonStore= url:'api/fail_parts_bydepart.php',250); line-height:18px"> 'loadexception':function(e){
  • alert(e.toString());
  • },250); line-height:18px"> {name:'name'},250); line-height:18px"> {name:'flash'},250); line-height:18px"> {name:'percent'}
  • jsonStore.load({
  • params:{
  • '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
  • //用法二
  • varstore={
  • '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']})
  • };
  • store.product.baseParams={'department':encodeURIComponent(data.data.name)};
  • store.product.load();
  • detailStore.on('beforeload',function(){
  • detailStore.baseParams={
  • });
  • JS中encodeURIComponent函数用php解码 在JS中使用了encodeURIComponent对中文进行编码在PHP中使用iconv('UTF-8','gb2312',$q);就可以得到你需要的字串了

    (编辑:李大同)

    【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

      推荐文章
        热点阅读