I am using dojo aspect.before to perform some actions prior to calling my original method. However, I am trying to cancel the original method if some criteria is not met within the aspect.before method, but not able to cancel that event.
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 is what you're looking for. It allows you to substitute the original method and apply it on your own terms.
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
}
}
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.