2013-02-26 5 views
1

아이콘 클릭과 함께 윈도우 그리드 레이아웃에 작업 열 아이콘이 있습니다. 그리고 아이콘을 클릭하면 나는 fieldset dynamicllay를 만들고 있습니다. 필드 세트에는 단추와 이미지가 포함됩니다. 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.'); 
        } 
       }) 
      } 

     }] 
    }) 

} 

내가 무엇입니까 문제는 내가 각 버튼의 같은 값을주고 (루프의 1 값) 낭포 방법의 모든 looping.But의 온 클릭으로 오는 동적 값을 받아 버튼의 핸들러를 원하는 것입니다 동적으로 만들어서 모든 이미지에 대해 매개 변수를 동적으로 전달할 수 있습니다.

+0

이 http://stackoverflow.com/questions/11204680/ext-js-pass-extra-param-to-handler – Ben

답변

1

범위 지정 문제가 있습니다. 당신이해야 할 일은 버튼 설정에서 변수를 잡는 것입니다.

당신은 같은 것을 할 수 있습니다

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

덕분에 많은 도움이 될 수 있습니다. 그것은 나를 위해 작동합니다. – anupkumar

관련 문제