2016-06-16 54 views
0

有没有办法在formatter函数中使用this运算符?我的意思是this对使用​​格式化程序的组件的引用。例如,我得到这个代码:。这里面fromatter功能

metadata : { 
     //includes : [ "../../css/orgstructure.css" ], 
     properties : { 
      ... 
      showId : { type : "boolean", defaultValue : true }, 
      .. 
    } 

//Some view stuff ... 

    columns : [ new sap.ui.table.Column({ 
       label : "Beschreibung (ID)", 
       filterProperty : "SHORT_TEXT", 
       template : new sap.m.Text().bindProperty("text", { 
        parts : [ { 
         path : "SHORT_TEXT", 
         type : new sap.ui.model.type.String() 
        }, { 
         path : "ID", 
         type : new sap.ui.model.type.String() 
        } ], 
        formatter : function(text, id) { 
         if (text != null && id != null) { 
          if(this.getProperty("showId)){ 
           return text + " (" + id + ")"; 
          }else{ 
           return text; 
          } 
         } 

         return ""; 
        } 
       }) 
      }) 

当我想用this.getProperty("showId)我得到一个异常访问属性showId,这个功能并不存在this。我知道如何绑定this到事件的功能,但是当函数被调用这个样子,我#已经得到了不知道如何处理这一点;)

回答

2

使用下面的语法只是绑定this的功能:

formatter : function(text, id) { 
    if (text != null && id != null) { 
     if(this.getProperty("showId)){ 
      return text + " (" + id + ")"; 
     }else{ 
      return text; 
     } 
    } 
    return ""; 
}.bind(this) 
+0

呃这么简单:)谢谢你帮助我 – Chris