簡體   English   中英

Dojo方面取消原方法

[英]Dojo aspect cancel original method

我正在使用 dojo aspect.before 在調用我的原始方法之前執行一些操作。 但是,如果在 aspect.before 方法中不滿足某些條件,我會嘗試取消原始方法,但無法取消該事件。

require(["dojo/_base/declare",
"dojo/_base/lang",
"dojo/aspect",
"dojo/dom",
"dojo/on"], 
function(declare, lang, aspect, dom, on) {
  aspect.before(target,"onSave", function(event){
     var mycriteria  = //some logic to determine this value;
     if(mycriteria == null || mycriteria == undefined){ 
         //cancel the "onSave" method.
         // if cancelling this is not possible, can I call "onCancel" method here that'll cancel this 
         //event?
     }
  });
}

aspect.around是您正在尋找的。 它允許您替換原始方法並按照您自己的條件應用它。

require(["dojo/_base/declare", "dojo/_base/lang", "dojo/aspect", "dojo/dom", "dojo/on"], function(declare, lang, aspect, dom, on) {
    aspect.around(target, "onSave", function(originalOnSave) {
        return function newOnSave() {//this function receives the parameters the onSave normally would. 
            var myCriteria = true;
            if (myCriteria) {
                //invoke original
                originalOnSave.apply(this, arguments);
            } else {//do nothing
            }
        }
    });
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM