2017-10-04 88 views
1

在SAPUI5中,通常可以通过多种方式将资源包属性绑定到项目。我正在尝试使用Odata服务提供的数据在JavaScript中执行此操作,但目前为止我在这里找到的方法没有奏效。我已经试过两种不同的方式:将ResourceBundle属性绑定到列表项

  1. How to Use Internalization i18n in a Controller in SAPUI5?

  2. binding issue with sap.m.List and model configured in manifest.json

而且,无论这些都工作过。我觉得这是因为我是一个项目列表里面,一个对话框,里面是造成我的问题:

我的代码是:

var resourceBundle = this.getView().getModel("i18n"); 

if (!this.resizableDialog) { 
    this.resizableDialog = new Dialog({ 
     title: 'Title', 
     contentWidth: "550px", 
     contentHeight: "300px", 
     resizable: true, 
     content: new List({ 
      items: { 
       path: path, 
       template: new StandardListItem({ 
        title: resourceBundle.getProperty("{Label}"),//"{ path : 'Label', fomatter : '.getI18nValue' }", 
        description: "{Value}" 
       }) 
      } 
     }), 
     beginButton: new Button({ 
      text: 'Close', 
      press: function() { 
       this.resizableDialog.close(); 
      }.bind(this) 
     }) 
    }); 

getI18nValue : function(sKey) { 
    return this.getView().getModel("i18n").getProperty(sKey); 
}, 

使用上面的第二个方法,从来没有调用JavaScript方法。我不认为它会起作用,因为它更基于JSON。第一种方法是加载数据,但不显示资源包文本,而是显示{Label}值内的文本。

{Label}中找到的值与资源束内部找到的值匹配,即没有前面的i18n>,就像您在视图中看到的一样。

任何人有任何建议吗?

回答

1

使用格式化程序会解决你的问题,但是你这样做的方式是错误的。试试这个,它会解决你的问题。

var resourceBundle = this.getView().getModel("i18n"); 
if (!this.resizableDialog) { 
    this.resizableDialog = new Dialog({ 
     title: 'Title', 
     contentWidth: "550px", 
     contentHeight: "300px", 
     resizable: true, 
     content: new List({ 
      items: { 
       path: path, 
       template: new StandardListItem({ 
        title: { 
         parts: [{ path: "Label" }], 
         formatter: this.getI18nValue.bind(this) 
        }, 
        description: "{Value}" 
       }) 
      } 
     }), 
     beginButton: new Button({ 
      text: 'Close', 
      press: function() { 
       this.resizableDialog.close(); 
      }.bind(this) 
     }) 
    }); 
} 

和格式化功能getI18nValue会是这样,

getI18nValue: function(sKey) { 
    return this.getView().getModel("i18n").getResourceBundle().getText(sKey); 
}, 
相关问题