2011-07-29 17 views
4

ウェブページのツリービューにjstreeを使用しています。[jsTree]:新しいノードで 'rename'イベントと 'move'イベントが発生しないのはなぜですか?

ツリーでは、ノードの名前を変更してノードを移動できます。ノードの移動または名前の変更は、rename_node.jstreeおよびrename_node.jstreeイベントを発生させます。

新しいノード(rename_node.jstree eventsで作成)では、ノードの名前を変更して移動できますが、move_node.jstreeイベントとrename_node.jstreeイベントは起動されません。

イベントは最初のノードでのみバインドされているようです。後で作成されるノードとイベントをバインドするための「ライブ」メソッドは表示されません。

これを行う可能性はありますか?ここで

は私の問題を理解するために(私は願っています)ことができますサンプルです:

$(function(){ 
    $("#nodes").jstree({ 
     "plugins" : [ "themes", "html_data", "dnd", "ui", "crrm" ] 
    }).bind("move_node.jstree", function (event, data) { 
     alert('move'); 
    }).bind("rename_node.jstree", function (event, data) { 
     alert('rename'); 
    }).bind("create_node.jstree", function (event, data) { 
     alert('create_node'); 
    }) 

    $("#create_button").click(function() { 
     $("#nodes").jstree("create",null,"last",{data:"name"}); 
    }); 
}); 
+0

これは、イベントの一部について説明しています。https://groups.google.com/d/msg/jstree/UIFqvVgmncQ/JsBVcbB-w5gJ –

答えて

2

イベントが正しく開始されたようです。問題はロジックのどこかにありました。私はアイテムのIDを正しく扱えるように設定しなければなりませんでした。

$("#nodes").jstree("create",null,"last",{data:the_name, attr: {id: the_id}}); 

この間違いをおかけして申し訳ありません。

5

コマンドはcreate_nodeある、ないcreate、私は思います。詳細はhttp://www.jstree.com/documentation/coreを参照してください。 FYI、あなたのコードが良いように記述されるだろう


$(function() { 
    $("#nodes").jstree({ 
     "plugins": ["themes", "html_data", "dnd", "ui", "crrm"] 
    }).bind("move_node.jstree rename_node.jstree create_node.jstree", function(event, data) { 
     var type = event.type; 
     alert(type); 
     if (type === 'move_node.jstree') { 
      //handle move_node.jstree here 
     } else if (type === 'rename_node.jstree') { 
      //handle rename_node.jstree here 
     } else if (type === 'create_node.jstree') { 
      //handle create_node.jstree here 
     } 

    }); 

    $("#create_button").click(function() { 
     $("#nodes").jstree("create", null, "last", { 
      data: "name" 
     }); 
    }); 
}); 

私はそれが主観的であるが、知っている価値がある何のためにそれを取ります。

+0

回答とアドバイスありがとうございます。 create_nodeを使っても、新しく作成したノードの名前を変更すると、rename_node.jstreeイベントが表示されないようです。私のイベントのコールバックに何か間違っているかもしれませんが、あなたのアドバイスで自分のコードをリファクタリングするのに少し時間が必要です。 – luc

+0

イベントを扱う方法が「正しい」方法である理由についてご意見をお聞かせください。 –

関連する問題