1
如何更改代碼,以便組合框顯示displayField值的列表時商店已經嵌套JSON數據。如何更改代碼,以便組合框顯示displayField列表值
當我通過組合框編輯欄中的「名」,它顯示了空單。
Ext.define("Model", {
extend: "Ext.data.Model",
fields: [
{name: "id", type: "int"},
{name: "name.name"},
{name: "phone", mapping: "name.phone"},
{name: "descr", type: "string", mapping:'description'}
]
});
// store with data that we will recieve from test echo ajax service
var Store = Ext.create("Ext.data.Store", {
model: "Model",
autoLoad: true,
proxy: {
type: 'ajax',
url: '/echo/json/',
actionMethods: {read: 'POST'}, // echo ajax service required
extraParams: {
json: Ext.JSON.encode({
root: [{id: 1, name: {name:"John", phone: "123"}, description:"Fapfapfap"},
{id: 2, name: {name:"Danny", phone: "234"}, description:"Boobooboo"},
{id: 3, name: {name:"Tom", phone: "345"}, description:"Tralala"},
{id: 4, name: {name:"Jane", phone: "456"}, description:"Ololo"},]
})
},
reader: {
type: 'json',
root: 'root'
}
},
});
// and finally I have a grid panel
Ext.create("Ext.grid.Panel", {
store: Store,
columns: [
{dataIndex: "id", header:"ID"},
{dataIndex: "name.name", header:"Name", flex: 1, editor: {xtype:"combo", store: Store, displayField:'name.name'}},
{dataIndex: "phone", header:"Phone", flex: 1, editor: "textfield"},
{dataIndex: "descr", header: "Description", flex: 2, editor: "htmleditor"}
],
//selType: 'rowmodel',
plugins: [Ext.create('Ext.grid.plugin.CellEditing')],
renderTo: Ext.getBody(),
});
這裏舉例:http://jsfiddle.net/3MknG/2/
當我將displayField更改爲錯誤的字段名稱時,Combobox下拉列表顯示空項目。但是,當displayField正確時,組合框下拉列表爲空。 –
不幸的是'ComboBox'使用'BoundList',它使用'collectData'方法從記錄中提取數據(參見[refresh](http://docs.sencha.com/ext-js/4-1/source/AbstractView.html #Ext-view-AbstractView-method-refresh)方法)。所以你的數據對象沒有''name.name''屬性,這就是爲什麼你有這個問題。我也認爲這是一個奇怪的行爲,所以也許你最好發佈一個錯誤報告。 –