2014-02-07 98 views
1

我想知道有人可以幫助我將對象數組的信息映射到使用ExtJS 4.2的組合框中。無法使用Ext JS 4映射組合框組件中的「顯示」和「值」字段。顯示[對象對象]

我已經在下面的圖像中描述的物體:

enter image description here

我想使用這種「產品」陣列作爲ComboBox組件中的存儲。

我所定義的組分如下:

var selector = { 
       xtype: 'fieldcontainer', 
       anchor: '50%', 
       layout: {type: 'hbox', pack: 'start'},   
       items: [{ 
        xtype: 'combobox',     
        allowBlank: false, 
        editable: false, 
        fieldLabel: 'Products (' + products.length + ')', 
        itemId: 'productsInvolved', 
        store: products, 
        displayField: 'key.productType', 
        valueField: 'key.productId'  
      }] 
      }; 
      return selector; 

但我不能找出爲什麼它返回:[對象物體]當我顯示它在用戶界面,它必須顯示「一般」和具有「123456」的值。

我已經嘗試將其轉換爲ArrayStore,但沒有成功。請提供一些想法或線索?

我真的很感謝你的幫助。提前致謝。最好的祝福。

回答

1

我會嘗試將兩個計算字段添加到您的模型是這樣的:在你的組合

Ext.define('Product', { 
    extend: 'Ext.data.Model', 
    fields: [ 
     { 
      name: 'keyProductType', 
      convert: function(value, record) { 
       return record.data.key.productType; 
       //or 
       //return record.get('Key').productType; 
      } 
     }, 
     { 
      name: 'keyProductId', 
      convert: function(value, record) { 
       return record.data.key.productId; 
       //or 
       //return record.get('Key').productId; 
      } 
     }, 
     .. 
     .. 
    ] 
}); 

然後用這些新字段名

displayField: 'keyProductType', 
valueField: 'keyProductId' 

注:我還沒有testeed這還沒有

-1

我建議只有一個在上面的代碼更改。

Ext.define('Product', { 
    extend: 'Ext.data.Model', 
    fields: [ 
     { 
      name: 'keyProductType', 
      convert: function(value, record) { 
       return record.data.key.data.productType; 
      } 
     }, 
     { 
      name: 'keyProductId', 
      convert: function(value, record) { 
       return record.data.key.data.productId; 
      } 
     }, 
     .. 
     .. 
    ] 
}); 

,然後在你的組合使用這些新的字段名

displayField: 'keyProductType', 
valueField: 'keyProductId'