2016-06-16 7 views
0

Gibt es eine Möglichkeit, den Operator this in einer Formatierungsfunktion zu verwenden? Ich meine mit this den Verweis auf meine Komponente, in der der Formatierer verwendet wird. Zum Beispiel habe ich diesen Code:.dieser Inhalt der Funktion

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 ""; 
        } 
       }) 
      }) 

Wenn ich die Eigenschaft showId mit this.getProperty("showId) ich eine Ausnahme erhalten zugreifen möchten, dass diese Funktion für this existiert nicht. Ich weiß, wie this an eine Event-Funktion zu binden, aber wenn die Funktion wie folgt aufgerufen wird, ich # habe keine Ahnung, wie das zu handhaben;)

Antwort

2

bindet Gerade this an die Funktion mit der folgenden Syntax:

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

Uh so einfach :) Danke für Ihre Hilfe – Chris

Verwandte Themen