2012-04-02 9 views
0

dojoツリーの値を変更して正しいアイコンを表示しようとしています。私はfetchItemByIdentity()を持つオブジェクトを取得し、そこに値を変更することができることをホッピングされましたが、itemnulldojoツリー・ノードの値を変更してください

私は助けを求めてうれしい
_target: null, 
    _treeModel: null, 

    constructor: function(target, uuid) { 
     this._target = target; 
     this._uuid = uuid; 

     // from somewhere else the value get's changed 
     topic.subscribe("questionChanged", lang.hitch(this, function(object, id) { 
      var item = this._treeModel.fetchItemByIdentity({ 
       identifier: id, 
       onItem: function(item, request) { alert("item " + item); } 
       }); 
     })); 
    }, 

    buildTree: function() { 
     xhr.get({ 
      // The URL to request 
      url: er.getAbsoluteUrl("/secure/staticquestion/tree?uuid=" + this._uuid), 
      handleAs: "json", 
      headers: { 
       "Content-Type": "application/json; charset=utf-8" 
      }, 
      preventCache: 'true', 
      // The method that handles the request's successful result 
      load: lang.hitch(this, function(response) { 
       var rawdata = new Array(); 
       rawdata.push(response); 
       var store = new ItemFileReadStore({ 
        data: { 
         identifier: "uuid", 
         label: "name", 
         items: rawdata 
        } 
       }); 
       this._loadtree(store); 
      }), 
      error: function(err, ioArgs) { 
       errorDialog.show(err.message); 
      } 
     }); 
    }, 

    _loadtree: function(store) { 
     this._treeModel = new TreeStoreModel({ 
      store: store, 
      query: { 
       name: 'root' 
      }, 
      childrenAttrs: [ "children" ], 
      mayHaveChildren: function(object) { 
       return object.children.length > 0; 
      } 
     }); 

     var tree = new Tree({ // create a tree 
      model: this._treeModel, // give it the model 
      showRoot: false, 
      getIconClass: function(/* dojo.data.Item */item, /* Boolean */opened) { 
       if (!item || this.model.mayHaveChildren(item)) { 
        return opened ? "dijitFolderOpened" : "dijitFolderClosed"; 
       } else if (item.comment == 'false') { 
        return (item.answer == 'YES') ? "dijitLeafNoCommentYes" 
          : ((item.answer == 'NO') ? "dijitLeafNoCommentNo" : "dijitLeafNoComment"); 
       } else if (item.comment == 'true') { 
        return (item.answer == 'YES') ? "dijitLeafYes" : ((item.answer == 'NO') ? "dijitLeafNo" 
          : "dijitLeaf"); 
       } 
       return "dijitLeaf"; 
      }, 
     }, this._target); // target HTML element's id 
     tree.on("click", function(object) { 
      topic.publish("staticQuestionSelected", object); 
     }, true); 
     tree.startup(); 
    } 

、感謝です!

答えて

0

私の問題を発見しました:ItemFileWriteStoreを使用する必要があります。store.setValue(item, attribute, value)で値を変更できます。その後ツリーが更新されます。

関連する問題