2017-05-10 26 views
1
Ext.define('Form', { 
    extend: 'Ext.data.Model', 
    fields: [ 
     {name:'type', type:'String'} 
    ] 
}); 

var store = Ext.create('Ext.data.ArrayStore', { 
    model: 'Form', 
    autoLoad: true, 
    proxy: { 

     type: 'ajax', 
     url: '/test.json', 
     reader: { 
      type : 'json', 
      root: 'types' 
     } 
    } 
}); 

Ext.define('DForms', { 
    extend: 'Ext.panel.Panel', 
    bodyPadding: 12, 
    layout : 'auto', 
    autoScroll : true, 

     items: [{ 
      xtype:'selectcombo', 
      queryMode:'local', 
      emptyText: 'Select Condition', 
      store:store, 
      displayField: 'type', 
      valueField: 'type', 
      width : 200, 
      typeAhead : true 
     }], 
}); 

当这种负载,selectcombo是空的,没有被加载时,我经历了许多的网站搜索,并不能找到任何帮助。任何建议将是巨大的使用JSON文件填充组合框,ExtJS的4.x.x

+0

给json文件contents.It会帮忙找到问题 – Tejas

回答

0

xtype你寻找的是combo,该store类型是JsonStore因为ArrayStore将不会从types根正如你所预料解释json。尽管如此,我无法模拟ajax请求。

Ext.onReady(function() { 
 

 
    Ext.define('Form', { 
 
    extend: 'Ext.data.Model', 
 
    fields: [{ 
 
     name: 'type', 
 
     type: 'String' 
 
    }] 
 
    }); 
 

 
    var store = Ext.create('Ext.data.Store', { 
 
    model: 'Form', 
 
    data: [{ 
 
     type: 'Aaaaaaa' 
 
    }, { 
 
     type: 'Bbbbbb' 
 
    }, { 
 
     type: 'Ccccccccccc' 
 
    }, { 
 
     type: 'Ddddddd' 
 
    }] 
 

 
    }); 
 

 
    Ext.define('DForms', { 
 
    extend: 'Ext.panel.Panel', 
 
    bodyPadding: 12, 
 
    layout: 'auto', 
 
    autoScroll: true, 
 
    items: [{ 
 
     xtype: 'combo', 
 
     queryMode: 'local', 
 
     emptyText: 'Select Condition', 
 
     store: store, 
 
     displayField: 'type', 
 
     valueField: 'type', 
 
     width: 200, 
 
     typeAhead: true 
 
    }], 
 
    }); 
 

 
    Ext.create('DForms', { 
 
    renderTo: Ext.getBody() 
 
    }); 
 

 
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/extjs/4.2.1/ext-all-debug.js"></script> 
 
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/extjs/4.2.1/resources/css/ext-all.css" />

+0

啊,谢谢!工作 – Ubiq

+0

如果它的工作标记它);谢谢,祝你好运! – bluehipy

+0

它不让我 – Ubiq

0

我觉得在字段中键入是区分大小写的。所以试试

fields :[{name : 'type', type : 'string'}] 

如果仍然不工作,就像Tejas1991指出的那样检查你的json的内容。

+0

是的,结合你和bluehipy,它工作:) – Ubiq