2017-11-22 6 views
0

XMLSAP UI5のコントローラに名前の値を渡す方法は?

table.bindItems({ 
       path: "/", 
       template: new sap.m.ColumnListItem({ 
        cells: [ 
         new sap.m.Text({ 
          text: "{account_name}" 
         }), 
         new sap.m.Button({ 
          text: "Disconnect", 
          name:"{account_id}", 
          press: [that.handleButtonPress, this] 
         }) 
        ] 
       }) 
      }); 

JS

handleButtonPress: function (oEvent) { 
} 
ここ

私はテーブルにJSONデータをバインドdynamicaly。私はそこに一つのボタンを置く。ボタンをクリックすると、コントローラーでその名前の値を取得する必要があります。これを行う方法..?

答えて

2

ボタンプレスハンドラに渡されたコンテキストをthisの代わりにthatに変更します。すなわち

table.bindItems({ 
      path: "/", 
      template: new sap.m.ColumnListItem({ 
       cells: [ 
        new sap.m.Text({ 
         text: "{account_name}" 
        }), 
        new sap.m.Button({ 
         text: "Disconnect", 
         name:"{account_id}", 
         press: [that.handleButtonPress, that] 
        }) 
       ] 
      }) 
     }); 

とあなたのコントローラで:

handleButtonPress: function (oEvent) { 
    console.log(this); // this is your controller. 
    var source = oEvent.getSource(); 
    console.log(source) // this is your button. 
    var oBindingObject = source.getBindingContext().getObject(); 
    console.log(oBindingObject.account_id);// will print the button text 

}

関連する問題