2013-02-26 136 views
1

我在網格佈局中有一個動作列圖標,點擊圖標我打開了一個窗口窗體面板。 然後點擊圖標我建立一個fieldset dynamicllay。 Fieldset包含按鈕和圖像。添加按鈕在EXTjs中動態點擊事件4

//Below is the code 
for (var j = 0; j < productPictures.length; j++) { 
    var values = productPictures[j].value; 
    var idPic = productPictures[j].idProductPicture; 
    alert(idPic); 
    fieldset.add({ 
     xtype: 'container', 
     layout: 'hbox', 
     items: [{ 
      xtype: 'box', 
      autoEl: { 
       tag: 'img', 
       src: '/files/product/' + idProduct + '/picture/100x75/' + values, 
       height: '50px', 
       width: '50px' 
      } 
     }, { 
      xtype: 'button', 
      name: 'remove' + idPic, 
      width: 200, 
      text: 'Remove', 
      handler: function() { 
       alert(idPic); 
       Ext.Ajax.request({ 
        url: '/admin/productpicture?id=' + idPic + '&memberId=' + idMember + '&idProduct=' + idProduct, 
        method: 'DELETE', 
        success: function (response) { 
         Ext.Msg.alert('Status', 'Image Deleted succesfullly.'); 
        }, 
        failure: function() { 
         Ext.Msg.alert('Status', 'There is an error.'); 
        } 
       }) 
      } 

     }] 
    }) 

} 

是我收到的問題是我想要的按鈕的處理程序,以接受與每個按鈕其給出相同的值(循環的第一個值)。所以,如何的每looping.But的onclick來動態值使其具有動態性,以便我可以動態地爲每個圖像傳遞參數。

+0

這可能有助於http://stackoverflow.com/questions/11204680/ext-js-pass-extra-param-to-handler – Ben 2013-02-26 12:21:49

回答

1

您遇到了範圍問題。你需要做的是將變量保存在按鈕配置中。

你可以做這樣的事情:

{ 
    xtype: 'button', 
    name: 'remove' + idPic, 
    idPic: idPic, 
    width: 200, 
    text: 'Remove', 
    handler: function (button) { 
     alert(button.idPic); 
     //the rest... 
    } 
} 
+0

非常感謝。這個對我有用。 – anupkumar 2013-02-26 12:36:25