FineUploader - 添加data-id以预览li

时间:2014-04-28 18:24:47

标签: jquery fine-uploader jquery-ui-sortable

我试图使用jQuerySortable和FineUploader。我在FineUploader上有以下回调:

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作为序列化方法,因此我需要将其添加到li回调中的预览onComplete。怎么办呢?

1 个答案:

答案 0 :(得分: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);
    }
}