2016-11-14 6 views
0

목록에 고유 한 값만 표시하려고합니다. 값은 다음 JSON 모델에서로드와 나는 모든 고유 한 이름으로 목록을 채울 필요가 있습니다 : 가능한 내가 sap.m.ListBinding 클래스로 실행 솔루션과 그 기능에 대한 검색하는 동안sap.m.List에 고유 한 값 표시

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

getDistinctValues(sPath) >>see API

이 함수는 주어진 상대 경로에서 고유 한 값의 배열을 반환해야합니다. 나는 다음과 같은 방식으로 기능을 사용하여 시도했다 :

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

하지만 난 arrValues=null가 계속. 여기에 내가 뭘 잘못하고 있는지에 대한 아이디어가 있습니까? 나는 또한 행운없이 customers>name, customers>/name/name을 사용해 보았습니다.

+0

새로운 ListBinding (oModel, "/ Customers")'을 사용해 보셨습니까? 컨텍스트를 사용하려면'새로운 ListBinding (oModel, "", oModel.getContext ("/ Customers"))'? ListBinding에는 배열을 가리키는 Path가 있어야합니다. – schnoedel

답변

0

getDistinctValues ​​()가 실패하거나 여러 속성에서 고유성을 측정해야하는 경우 아래 기술이 유용 할 수 있습니다. 본 유스 케이스는 입력 상자 제안이지만 I의 테크닉을 제공

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(); 
    }, 

필터 생성자로 전달 이내에 기능 고유성 테스트 및 배열에 일치하는 추가 논리를 포함하는 등

이 방법은 주제가 해제되면 알려주고 답변을 삭제합니다.