3
我想實現類似http://thejekels.com/dojo/cbtree_AMD.htmlDijit的複選框樹事件代表團
dijit的複選框樹和壓倒一切的像這樣的方法:
connect.connect(tree, "_onExpandoClick", model, this,function(/*data.item*/ item) {
console.log("My onExpandoClick");
});
Dijit的樹JavaScript文件中已經包含了此事件的處理方法。我的問題是
我想樹js的方法處理後調用上面覆蓋方法 一直按現在它總是叫first.Any想法executed.As。(來dijit 1.7)
在我的設置下面的代碼不起作用:
require(["dijit/TitlePane"]);
require([
"dojo/_base/lang",
"dojo/dom",
"dojo/aspect",
"dijit/CheckboxTree",
"dojox/data/JsonRestStore",
"my_ext/CheckboxForestStoreModel",
"dojo/domReady!"
], function(dom, Tree, JsonRestStore, CheckboxForestStoreModel) {
var treeStore = new JsonRestStore({ target: "ObjectTreeServlet/",labelAttribute:"name",allowNoTrailingSlash:true});
var treeModel = new CheckboxForestStoreModel({
store: treeStore,
deferItemLoadingUntilExpand: true,
rootId: "ROOT",
rootLabel: "NETWORK",
childrenAttrs: ["children"],
query:"?id=0"
});
var treeStateSession= '<%=session.getAttribute("treeState")%>';
//alert(treeStateSession);
var tree = new Tree({
id : "tree",
model : treeModel,
showRoot : false,
persist: true,
setCheckboxOnClick : false,
_sessionVal:treeStateSession
},
'treeDiv');
function getParameterByName(url,name) {
var match = RegExp('[?&]' + name + '=([^&]*)')
.exec(url);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
dojo.require("dojo.aspect");
/*
aspect.after(tree, "_onExpandoClick", function(item) {
console.log(tree.getSessionValue());
document.getElementById("treeState").value=tree.getSessionValue();
console.log(document.getElementById("treeState").value.length);
}); */
aspect.after(tree, "_onExpandoClick", function() {
console.log("My onExpandoClick");
});
代碼中CheckBoxTree.js:
_state: function(node, expanded){
// summary:
// Query or set expanded state for an node
if(!this.persist){
return false;
}
var path = array.map(node.getTreePath(), function(item){
return this.model.getIdentity(item);
}, this).join("/");
if(arguments.length === 1){
return this._openedNodes[path];
}else{
if(expanded){
this._openedNodes[path] = true;
}else{
delete this._openedNodes[path];
}
var ary = [];
for(var id in this._openedNodes){
ary.push(id);
}
//console.log(ary.length);
//cookie(this.cookieName, ary.join(","), {expires:365});
var sessionVal=ary.join(",");
console.log("TreeSTATE CheckBOX");
**//FROM HERE SEND sessionVal TO MAIN HTML PAGE WHERE TREE IS CREATED?**
//this.getSessionValue(ary.join(","));
}
},
我試了一下,這是不是給預期的效果:
aspect.after(tree, "_state", function() {
console.log("TreeSTATE " + tree.getSessionValue());
document.getElementById("treeState").value=tree.getSessionValue();
});
我不知道你是什麼所以我放了一個例子,請看看它,讓我知道你不喜歡那裏:[http://jsfiddle.net/phusick/LcPzv/](http://jsfiddle.net/phusick/LcPzv /)。還要注意,'Tree'發出'open'事件,所以你可以添加監聽器來代替:'tree.on(「open」,function(item,node){})''。 – phusick
嗨,已經粘貼了代碼。它說JsonTreeStore不是一個構造函數。如果我們刪除了你建議的兩個要求,樹就會出現。任何幫助? – Muse
'JsonRestStore'不是構造函數,因爲'JsonRestStore'變量是'dojo/aspect'模塊。 'require([/ * Array * /],function(){/ * Factory * /})' - require _array_中的項必須與_factory_函數中的參數匹配。另外[AMD loader](http://livedocs.dojotoolkit.org/loader/amd)是異步的,因此'require([「dijit/TitlePane」])在您的工廠函數中不可用。不要混合傳統的'dojo.require()'和AMD'require()/ define()'。選擇一個並堅持下去。 – phusick