Skip to Content
0
Former Member
May 25, 2016 at 03:13 PM

How to show only unique values from a json file into combo box .. if there are multiple records containing the same name

2408 Views

How to show only unique values from a json file into combo box .. if there are multiple records containing the same name..

In my example: I have created a combo box shows list of countries ..data binded from json file..

Suppose the country name gets repeated in more than 1 record. How to not add repeated (same) name twice on combo box ?

below you can find the code i have used:

js.view

var page1 = new sap.m.Page("p1",{});

var oModel = new sap.ui.model.json.JSONModel({});

oModel.loadData("Item/data.json");

var page1 = new sap.m.Page("p1",{title:"Main Page"});

var label1 = new sap.ui.commons.Label("l1",{text:"Country});

var cBox1 = new sap.ui.commons.ComboBox("cb1",{

value:"{/data}"

});

label1.setLabelFor(cBox1);

var listitem1 = new sap.ui.core.ListItem().bindProperty("text","Country");

cBox1.bindAggregation("items","/data",listitem1);

cBox1.setModel(oModel);

cBox1.bindValue("/selection");

page1.addContent(cBox1);

json file

{

"selection": "",

"data": [

{

"Country":"India",

"Type": "[All]",

},

{

"Country": "USA",

"Type":"[all]",

}

]

}

Suppose if i include another record in json file

{

"Country":"USA",

"Type": "[All]",

}

USA should not been shown on combo box.. because it is alrready present.

Please help me regarding this as i'm new to UI 5.. Thanks in advance..