如何删除重复项并在ViewSettingsItem中仅显示唯一值?

我正在从后端获取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>


不负相思意
浏览 284回答 2
2回答

哔哔one

您可以使用reduce和anObject来跟踪先前添加的内容sId'slet 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)=>{&nbsp; if(!track[inp.sId]){&nbsp; &nbsp; op.push(inp)&nbsp; &nbsp; track[inp.sId] = inp&nbsp; }&nbsp; return op},[])let op = {d:{results:results}}console.log(op)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript