2017-05-10 43 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