我正在从后端获取JSON数组中的重复值,并且我想删除重复值并仅在SAPUI5 ViewSettingsItem中显示唯一值。请帮助我。{"d": { "results": [{ "Status": "Completed", "sId": "C1" }, { "Status": "Completed", "sId": "C1" }, { "Status": "Started", "sId": "S1" }, { "Status": "In Process", "sId": "P1" },{ "Status": "Completed", "sId": "C1" }]}}XML视图:<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core"> <ViewSettingsDialog > <filterItems> <ViewSettingsFilterItem> <items> <ViewSettingsItem text="{Status}" key="{sId}"/> </items> </ViewSettingsFilterItem> </filterItems> </ViewSettingsDialog></core:FragmentDefinition>
2 回答
哔哔one
TA贡献1854条经验 获得超8个赞
您可以使用reduce和anObject来跟踪先前添加的内容sId's
let obj = {"d": {"results": [{"Status": "Completed","sId": "C1"}, {"Status": "Completed","sId": "C1"},{"Status": "Started","sId": "S1"},{"Status": "In Process","sId": "P1"},{"Status": "Completed","sId": "C1"}]}}
let track = {}
let results = obj.d.results.reduce((op,inp)=>{
if(!track[inp.sId]){
op.push(inp)
track[inp.sId] = inp
}
return op
},[])
let op = {d:{results:results}}
console.log(op)
添加回答
举报
0/150
提交
取消