English 中文(简体)
使用 j窗内的假肢,始终采用清理方法
原标题:Use jQuery Deferred inside plugin to always call cleanup method

页: 1 在这种假想中,当发生行动时,我会援引一种原始选择作为背书。 这一反馈一旦完成,我就希望实施一些清理法。

更具体地说,我的花gin利用了可干和可 drop。 关于可投放的drop,我援引“<>update>/strong>中所确定的职能。 在打电话后,我要作一些清理。 我不想要求花钱的使用者履行这一清理呼吁;我希望,在更新的非洲-日本宇宙航空研究开发机构方法成功之后,清理工作将自动进行。

我在此认为,利用被推迟的“金”是有意义的。 下面是关于“执行:

self.connectedLists = $(self.options.connectWith)
    .not(self.list)
    .droppable({
        hoverClass:  ui-selectablelist-active ,
        drop: function(e, ui) {
            var sender = $(ui.draggable).closest( ul ),
                deferred = self.options.update.call(self, e, {
                    sender: sender,
                    receiver: $(this),
                    items: selectedItems
                });

            deferred.then(function () {
                self.removeSelectedItems();
            });
        }
    });

而原始执行者守则则认为:

update: function (e, ui) {
    var self = this;
    return $.post(url, 
            {                 
                // some data                         
            })
            .done(function (data) {
                console.log( updated! );
            });
}

我将日本宇宙航空研究开发机构的呼吁退回到drop的背后。 在退席后,我想开展清理工作,removeS selectedItems总是使用......then()功能。 看来没有变化。

这种模式是否好像好主意。 谁能帮助我进行这一设计? 为什么在<<>drop>呼回的<>内,我做不到什么?

最佳回答

而不是使用<代码>.then,使用.always

<代码>then用于向推迟的物体添加提示:

deferred.then(donecallbacks,failcallbacks)

Try:

self.connectedLists = $(self.options.connectWith)
    .not(self.list)
    .droppable({
        hoverClass:  ui-selectablelist-active ,
        drop: function(e, ui) {
            var sender = $(ui.draggable).closest( ul ),
                deferred = self.options.update.call(self, e, {
                    sender: sender,
                    receiver: $(this),
                    items: selectedItems
                });

            deferred.always(function () {
                self.removeSelectedItems();
            });
        }
    });

<>Update:

由于开发商将指定更新功能,开发商总是有可能不把被推迟的物体适当退还给你。 你们应对此进行核查,并在此案中表现出 ex意。

self.connectedLists = $(self.options.connectWith)
    .not(self.list)
    .droppable({
        hoverClass:  ui-selectablelist-active ,
        drop: function(e, ui) {
            var sender = $(ui.draggable).closest( ul ),
                deferred = self.options.update.call(self, e, {
                    sender: sender,
                    receiver: $(this),
                    items: selectedItems
                });
            if (deferred.always) {
                deferred.always(function () {
                  self.removeSelectedItems();
                });
            }
            else {
                $.error("Update must return a deferred object.");
            }
        }
    });
问题回答

暂无回答




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签