我正在使用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.before中的某些条件不满足时,我试图取消原方法。 就是你要找的东西。它可以让你代替原来的方法,并根据自己的条件应用。
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
}
}
});
});