[英]custom callback on jquery event
我正在使用jquery和jstree
我有一個事件,每次我的樹變時都會觸發:
$tree.jstree()
.on("changed.jstree", function(event, target) {
//manipulate data
});
完美的作品。 我可以訪問“ this”(樹)以及事件和目標。 但是,我正在嘗試定義一個自定義回調。 我嘗試過這樣的事情:
window.customCallback = (function(event, target) {
//manipulate data
//$(this).foo() manipulates the tree
//event.type to access the event type
//target.node to access the node
}(this));
所以我可以使用:
$tree.jstree()
.on("changed.jstree", customCallback(event, target));
但這是行不通的。 有人可以幫我嗎?
$ tree.jstree()。on(“ changed.jstree”,customCallback(event,target));
您正在做的是將customCallback
的結果設置為回調處理程序。
您要做的是將函數本身設置為回調處理程序:
var customCallback = function(event, target) {
// ...
};
$tree.jstree().on("changed.jstree", customCallback);
注意“缺失”括號-因為括號會調用該函數,我們不希望這樣。
參數將自動傳遞給處理程序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.