0
amplify.subscribe("WorkTypesReceived", function () {

    var workTypesList = amplify.store("ExpenseWorkTypesFor" + JobNo_);
    amplify.unsubscribe("WorkTypesReceived");

});

getDropdownExpenseWorkTypes(JobNo_);

getDropdownExpenseWorkTypes调用了一个在完成时发布的函数"WorkTypesReceived"。但由于我在一个页面上不止一次调用整个函数,它呈指数级增长(同一主题的多个订阅)。我想在订阅发布一次后删除订阅(因此进入订阅功能一次)。

该行amplify.unsubscribe("WorkTypesReceived")似乎不起作用,文档说我需要第二个参数作为回调函数。但我在回调函数内部,所以不确定如何继续。

4

1 回答 1

4

如果您在回调中添加名称,您可以使用它来取消订阅...

amplify.subscribe( "WorkTypesReceived", function storeWork() {
    var workTypesList = amplify.store( "ExpenseWorkTypesFor" + JobNo_ );
    amplify.unsubscribe( "WorkTypesReceived", storeWork );
});
于 2012-11-18T16:14:09.187 回答