on 03-24-2015 3:41 PM
I have a sap.m.List that I create the list items from a JSON model (named model as "mainMenu"), the model is attached to my JSON view
{
"mainMenu": [{
"title": "Literature",
}, {
"title": "Video",
}, {
"title": "Presentations",
}]
}
To create the list, in my JSON view I use a list template...
var oListTemplate = new sap.m.StandardListItem({
title: "{title}",
type: sap.m.ListType.Navigation,
});
My issue is that I have a i18n resource model set on this view as well.
mainMenu_Literature=Literature
mainMenu_Video=Video
mainMenu_Presentations=Presentations
In my template I can't use...
title: "{i18n>?}"
because I have nothing to put into the ? spot.
What I'd like to do is change my JSON model to...
{
"mainMenu": [{
"title": "mainMenu_Literature",
}, {
"title": "mainMenu_Video",
}, {
"title": "mainMenu_Presentations",
}]
}
Then in the template use...
var oListTemplate = new sap.m.StandardListItem({
title: "{i18n>{mainMenu>/title}}",
type: sap.m.ListType.Navigation,
});
But, of course, that binding syntax is a fantasy.
My my problem is clear, I want to use the value of one model as the key to the second.
Suggestions?
Thanks.
Hi Dean,
I tend to use a formatter function which returns the internationalized value for the model-bound property.
See my answer on a similar question on Stackoverflow: How is localized data binding set up with JSON files and XML views?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Looks like formatter functions only work in XML and HTML views?
I'm using a JS view like this.
This is in my sap.ui.jsview("SP.view.mainMenu") view declaration
var oListTemplate = new sap.m.StandardListItem({
title: "{path: 'title', formatter: '.getI18nValue'}",
type: sap.m.ListType.Navigation
});
And this is on my sap.ui.controller("SP.view.mainMenu") declaration
getI18nValue: function (sKey) {
return this.getView().getModel("i18n").getProperty(sKey);
}
and I get a console error "formatter function .getI18nValue not found!"
So either formatter functions don't work in JS views or I'm not declaring my formatter function correctly or in the right file.
I think I'm probably still doing something wrong.
Hello Dean,
I am wondering why you have the "." before the function name in the formatter?
var oListTemplate = new sap.m.StandardListItem({
title: "{path: 'title', formatter: '.getI18nValue'}",
type: sap.m.ListType.Navigation
});
The issue seems to be because your function is not getting resolved.
You could look at having a separate Formatter class , for eg : 'SP.view.mainMenu.Formatter' , have all the formatter functions in this class. You could then load this file using jQuery.sap.require('SP.view.mainMenu.Formatter') and then add the formatter function in your binding as follows:
var oListTemplate = new sap.m.StandardListItem({
title: "{path: 'title', formatter: 'SP.view.mainMenu.Formatter.getI18nValue'}",
type: sap.m.ListType.Navigation
});
Regards,
Radhika
For a declarative view (XML, HTML) the "dot" in front of the function name is to let the view know that the formatter function can be found in the controller.
I solved this by using a factory function instead of a template to create the list items.
By using the function I was able to get the key from mainMenu model then query the i18n model using that key.
I will try your idea when I have some time to re-visit this in my application.
Thanks.
Please mark this Discussion with a Correct Answer and Helpful Answer where appropriate. See http://scn.sap.com/community/support/blog/2013/04/03/how-to-close-a-discussion-and-why Even if you discovered the solution without any outside contributions, it helps others to understand what the solution turned out to be.
Regards, Mike (Moderator)
SAP P&I Technology RIG
User | Count |
---|---|
82 | |
10 | |
10 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.