2014-04-28 21 views
0

我想要用戶jQuerySortable和FineUploader。我已經在FineUploader以下的回調:FineUploader - 添加數據ID預覽li

callbacks: { 
    onComplete: function(id, name, response) { 
     this.setDeleteFileParams({ 
      attachment_id: response.attach_id, 
      action: 'delete_attachment', 
      nonce: response.delete_nonce 
     }, id); 

     $(".qq-upload-list-selector").sortable({ 
      onDrop: function (item, container, _super) { 
       var data = $(".qq-upload-list-selector").sortable("serialize").get(); 
       var jsonString = JSON.stringify(data, null, ' '); 
       console.log(jsonString); 
       _super(item, container) 
      } 
     }); 
    } 
} 

的jQuerySortable使用data-id的序列化方法,所以我需要它在onComplete回調添加到預覽li。如何才能做到這一點?

+0

什麼是「data-id」? –

+0

對不起,我需要添加''li'像'

  • ',其中id是'response.attach_id'。 – user1049961

    回答

    1

    首先,獲取文件容器元素的句柄,然後找到適當的子元素。最後,添加所需的屬性。

    callbacks: { 
        onComplete: function(id, name, response) { 
         var fileContainer = this.getItemByFileId(id), 
          $child = $(fileContainer).find("{{CHILD ELEMENT SELECTOR HERE}}"); 
    
         $child.attr("data-id", response.attach_id); 
        } 
    } 
    
    +0

    謝謝,效果很好 – user1049961