I'm trying to display only unique values in a List. The values are loaded from the following JSON Model and I need to populate the List with all unique names:
{"Customers": [
{"name": "Customer A","age": "30"},
{"name": "Customer B","age": "25"},
...
]}
While searching for a possible solution i ran into the sap.m.ListBinding class and its function getDistinctValues(sPath)
>> see API
This function should be returning an array of distinct values from a given relative Path. I've tried using the function in the following manner:
var oModel = this.getView().getModel("customers"),
oListBinding = new ListBinding(oModel, "customers>Customers", oModel.getContext("/Customers")),
arrValues = oListBinding.getDistinctValues("name");
But i keep getting arrValues=null
. Any ideas to what I'm doing wrong here?
I've also tried using customers>name
, customers>/name
and /name
without any luck.