2015-10-20 61 views
1

我有一个multicomboBox,我想绑定与json中的所有键multicomboBox。我使用XML视图。 我需要multicomboBox与值的productId,名称,类别,suppliername ..as如下设置与所有关键元素MulticomboBox

我的XML的观点是

<MultiComboBox selectionChange="handleSelectionChange" selectionFinish="handleSelectionFinish" width="300px" 
    items="{ 
        path: '/Collection', 
        sorter: { path: 'Name' } 
       }"> 

    <core:Item key="{ProductId}" text="{Name}" /> 
     </MultiComboBox> 

我的JSON文件

{ 
    "Collection": [ 
    { 
    "ProductId": "1", 
    "Name": "A", 
    "Category": "Projector", 
    "SupplierName": "Titanium", 
    "Description": "A very powerful projector with special features for Internet usability, USB", 
    "WeightMeasure": 1467, 
    "WeightUnit": "g", 
    "Price": 856.49, 
    "CurrencyCode": "EUR", 
    "Status": "Available", 
    "Quantity": 3, 
    "UoM": "PC", 
    "Width": 51, 
    "Depth": 42, 
    "Height": 18, 
    "DimUnit": "cm" 

    }, 
    { 
    "ProductId": "2", 
    "Name": "B", 
    "Category": "Graphics Card", 
    "SupplierName": "Technocom", 
    "Description": "Gladiator MX: DDR2 RoHS 128MB Supporting 512MB Clock rate: 350 MHz Memory Clock: 533 MHz, Bus Type: PCI-Express, Memory Type: DDR2 Memory Bus: 32-bit Highlighted Features: DVI Out, TV Out , HDTV", 
    "WeightMeasure": 321, 
    "WeightUnit": "g", 
    "Price": 81.7, 
    "CurrencyCode": "EUR", 
    "Status": "Discontinued", 
    "Quantity": 10, 
    "UoM": "PC", 
    "Width": 34, 
    "Depth": 14, 
    "Height": 2, 
    "DimUnit": "cm" 
    }, 
    { 
    "ProductId": "3", 
    "Name": "C", 
    "Category": "Graphics Card", 
    "SupplierName": "Red Point Stores", 
    "Description": "Hurricane GX: DDR2 RoHS 512MB Supporting 1024MB Clock rate: 550 MHz Memory Clock: 933 MHz, Bus Type: PCI-Express, Memory Type: DDR2 Memory Bus: 64-bit Highlighted Features: DVI Out, TV-In, TV-Out, HDTV", 
    "WeightMeasure": 588, 
    "WeightUnit": "g", 
    "Price": 219, 
    "CurrencyCode": "EUR", 
    "Status": "Out of Stock", 
    "Quantity": 25, 
    "UoM": "PC", 
    "Width": 34, 
    "Depth": 14, 
    "Height": 2, 
    "DimUnit": "cm" 
    }, 
    { 
    "ProductId": "4", 
    "Name": "D", 
    "Category": "Accessory", 
    "SupplierName": "Technocom", 
    "Description": "Web camera, color, High-Speed USB", 
    "WeightMeasure": 700, 
    "WeightUnit": "g", 
    "Price": 59, 
    "CurrencyCode": "EUR", 
    "Status": "Available", 
    "Quantity": 22, 
    "UoM": "PC", 
    "Width": 18, 
    "Depth": 19, 
    "Height": 21, 
    "DimUnit": "cm" 
    }, 
    { 
    "ProductId": "5", 
    "Name": "E", 
    "Category": "Accessory", 
    "SupplierName": "Technocom", 
    "Description": "Lock for Monitor", 
    "WeightMeasure": 40, 
    "WeightUnit": "g", 
    "Price": 13.49, 
    "CurrencyCode": "EUR", 
    "Status": "Available", 
    "Quantity": 30, 
    "UoM": "PC", 
    "Width": 11, 
    "Depth": 11, 
    "Height": 3, 
    "DimUnit": "cm" 
    } 
    ] 
} 

回答

1

我不认为不用创建新的数据对象就可以做你正在问的东西,原始对象的键将变成值。

在这里,我会怎么做(虽然我不使用XML的观点多):

<core:View 
    controllerName="local.controller" 
    xmlns:mvc="sap.ui.core.mvc" 
    xmlns:core="sap.ui.core" 
    xmlns="sap.m"> 
    <MultiComboBox width="300px" 
     items="{ 
     path: '/data', 
    }"> 

     <core:Item text="{value}" /> 
    </MultiComboBox> 
</core:View> 

在控制器中,我们做一个新的对象和模型:

var oModelData={}; 
oModelData.data = []; 
for(var key in oData.Collection[0]){ 
    var oObj = {}; 
    oObj.value = key; 
    oModelData.data.push(oObj); 
} 

oView.setModel(new sap.ui.model.json.JSONModel(oModelData)); 

这里是一个工作JSBIN例如:LINK

+0

我已经创建了相同的想法,但我需要在productId,名称,供应商名称的组合框中键...我想这个东西不是值。 –

+0

@sarathchambayil看看最新的答案。我不清楚你到底想要什么。对于那个很抱歉。 – keshet

+0

我创建了另一个对象,如你所说的键 –

0

也许是错过了一点,但您发布的原始代码应该正常工作。你想要的究竟是什么?