2016-11-14 8 views
0

リストに一意の値のみを表示しようとしています。 >>私はsap.m.ListBindingクラスとその機能getDistinctValues(sPath)に走った可能性のある解決策を探している間sap.m.Listに一意の値を表示

{"Customers": [ 
{"name": "Customer A","age": "30"}, 
{"name": "Customer B","age": "25"}, 
... 
]} 

:値は、次のようなJSONモデルからロードされていると私はすべてのユニークな名前でリストを移入する必要がありますsee API

この関数は、特定の相対パスから異なる値の配列を返す必要があります。私は、次のように関数を使って試してみた:

var oModel = this.getView().getModel("customers"), 
oListBinding = new ListBinding(oModel, "customers>Customers", oModel.getContext("/Customers")), 
arrValues = oListBinding.getDistinctValues("name"); 

しかし、私はarrValues=nullを得続けます。私がここで間違っていることにどのようなアイデア? 私はまた、customers>namecustomers>/name/nameを使ってみました。

+0

あなたは '新しいListBinding(oModel、"/Customers ")'を試しましたか?または、コンテキストを使用する場合は '新しいListBinding(oModel、" "、oModel.getContext("/Customers "))' ListBindingには、配列を指すPathが必要です。 – schnoedel

答えて

0

getDistinctValues()が失敗したり、複数の属性にまたがって識別性を測定する必要がある場合は、以下の手法を使用できます。このユースケースは、私は技術のためにそれを提供する入力ボックスの提案のためのものであるにもかかわらず:

handleSuggestClient: function(oEvent){ 
     var sValue = oEvent.getParameter("suggestValue"); 
     var filters = []; 
     var uniqueNames = []; 
     filters = [new sap.ui.model.Filter([ 
       new sap.ui.model.Filter("", function(oNode) { // blank first param passes in entire node to test function 
        var sVal = ((oNode.client + oNode.contact) || "").toUpperCase() 
        if (uniqueNames.indexOf(sVal) === -1){ 
         uniqueNames.push(sVal); 
         return sVal.indexOf(sValue.toUpperCase()) > -1; 
        } else { 
         return false; 
        } 
       }) 
     ], false)]; 
     this.oSFClient.getBinding("suggestionItems").filter(filters); 
     this.oSFClient.suggest(); 
    }, 

関数フィルタコンストラクタに渡さ等

、一意性をテストし、配列にマッチを追加するためのロジックを含む内これがオフの場合は、私に知らせてください、私は答えを削除します。

関連する問題