2014-02-07 181 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'