0

I have a JSON Model say:-

var currency = new sap.ui.model.json.JSONModel();
var currenices = [{"name":"Indian National Rupee", "code":"INR"},
                  {"name":"Euro", "code":"EUR"},
                  {"name":"U.S.Dollars", "code":"USD"},
                  {"name":"Chilean Peso", "code":"CLP"},
                  {"name":"New Zealand Dollar", "code":"NZD"}]
currency.setData(currenices);

How can I apply "new sap.ui.model.Filter(sPath, FilterOperator, value1, value2,...,...)" to this model. I want to get the currency name given the code. I know this can be done during data binding, but I want to do this directly to the model.

I applied the 'filter' function to the array and was able to filter the name given the code. Is It possible to do the same using model.Filter?

Thanks in Advance,

Deepak
  • 505
  • 1
  • 9
  • 32
  • Not sure what you're after... do you want to find the 'name' for a certain 'code' (i.e., something like the sql SELECT name WHERE code = 'EUR') or do you need a filter (i.e., reducing your list to a single entry)? – Qualiture Aug 21 '14 at 09:01
  • I want to get the name given the code (same as the sql you mentioned). I have a value help input box for curency which needs to be prepopulated as soon as user navigates to this page. I only get the currency code from the service and hence I have created a UI model to map the currency code to currnecy name and display the currency name on the input box always. So if I get 'USD' from the service, I display U.S.Dollars in the input box.currently I am using 'foreach' to loop through the array(currencies) and map the code to get the name. please let me know if there is a better way. – Deepak Aug 24 '14 at 04:28

1 Answers1

0

It is not possible. The Filter is bound to List Binding. Please see my answer in this post about Filter function in UI5 data binding. Why do you want to do this directly to the model?

Regards, Allen

Updated Answer:

Formatter function for data binding seems to be one solution for your case. Since you can maintain your own Currency Map, you can define the formatter and do the following:

var currencyMap = {"EUR":"Euro","USD":"U.S.Dollars"} // 

currencyFormatter: function(sCurrency) {

    return currencyMap[sCurrency];  
}

Details about UI5 formatter function, please see the documentation.

Community
  • 1
  • 1
Haojie
  • 5,665
  • 1
  • 15
  • 14