質問

私が使っているjQueryのdynaTreeアダプタのご使用をおとしなければいけませんのすべての子ノードをぶら下げるフィールドプログラムが親ノードを選択します。の構造のツリーが

<div id = "tree">
    <ul>
       <li>package 1
         <ul>
           <li>module 1.1
              <ul>
                <li> document 1.1.1</li>
                <li> document 1.1.2</li>
               </ul>
            </li>  
            <li>module 1.2
               <ul>
                 <li>document 1.2.1</li>
                 <li>document 1.2.2</li>
               </ul>
           </li>
        </ul>
     </li>
     <li> package 2
        <ul>
          <li> module 2.1
            <ul>
               <li>document 2.1.1</li>
               <li>document 2.1.1</li>
            </ul>
          </li>
        </ul>
      </li>
    </ul>
</div> 

何をしたいときクリックでツリーノードのタイトル"パッケージ1"そのすべての子ノードi.e(モジュール1.1、文書1.1.1、文書1.1.2、モジュール1.2文書1.2.1、文書1.2.2)でも、同様の処理が行われます。

以下のアプローチしていま利用しようとした:

$("#tree").dynatree({
        onSelect: function(flag, dtnode) {
            // This will happen each time a check box is selected/deselected
            var selectedNodes = dtnode.tree.getSelectedNodes();
            var selectedKeys = $.map(selectedNodes, function(node) {

                //alert(node.data.key);
                return node.data.key;


            });
            // Set the hidden input field's value to the selected items
            $('#SelectedItems').val(selectedKeys.join(","));

            if (flag) {
                child = dtnode.childList;

                alert(child.length);
                for (i = 0; i < child.length; i++) {
                    var x = child[i].select(true);
                    alert(i);
                 }
            }
        },
        checkbox: true,
        onActivate: function(dtnode) {
            //alert("You activated " + dtnode.data.key);
        }


    });

if(flag) 条件を取得しますすべての子ノードをぶら下げるフィールドの要素を選択したユーザーによると、この値が正しくできたらいいのからalert(子供です。長文です。そのループを選択すべての子どもがループが使えなくなることはありませんの声明 var x = child[i].select(true);

とができませんの声明 alert(i) れを実行します。の結果、上記の計算書であれば選択パッケージ1では、モジュール1.1書1.1.1ものを選択し、を実行し alert(i) 算書-他のお子様パッケージ1が選択されています。私が初めて child[i].select(true) 文が実行されるまでトリガーの選択イベント子どもが繰り返ようなことがいえるでしょう

私は考えますかね?何再帰さかの地球上では完結しませんのループを実行しても、次の命令 alert(i).

力を貸してくださいこの問題を解決.私は死亡するアラート、駐日アンゴラ共和国大使館特命全援の程、お願い申し上げます。

役に立ちましたか?

解決

かろうじてテストしていますが、このような何かを試すことができます:

$(function(){
    var inEventHandler = false;
    $("#tree").dynatree({
        checkbox: true,
        selectMode: 2,
        [...]
        onSelect: function(select, dtnode) {
            // Ignore, if this is a recursive call
            if(inEventHandler) 
                return;
            // Select all children of currently selected node
            try {
                inEventHandler = true;
                dtnode.visit(function(childNode){
                    childNode.select(true);
                });
            } finally {
                inEventHandler = false;
            }
        }

他のヒント

がない専門家のDynatreeの内容を書いた一部のコードを生成するパン粉をクリックノードとそのすべての子孫に当たります。

例示"をクリックすedibles"が出力:

edibles
edibles > fruits
edibles > fruits > apples
edibles > fruits > apples > green apples
edibles > fruits > apples > green apples > granny smith
edible > vegetables
edible > vegetables > potatoes

をクリックした"グリーンケミストリー"リンゴ"という出力:

edibles > fruits > apples > green apples
edibles > fruits > apples > green apples > granny smith

できるインスピレーションを得るからこの例では、取得の分野から必要なすべての書類を生成するHTMLを出力します。

このコードがこのスレッド:ベスト生成するようなテキストのパン粉でからPHPの配列を3ラム(id、パス名)?

のPHPスクリプトそのものであればDynatreeのonActivateイベントハンドラを通して jQuery.ajax({...}); を返します。

使用 mar10のの答えから1の代わりに、次の関数ます。

すべての子ノードが選択されている/非選択親ノードに選択/選択解除ます。

onSelect: function (isSelected, node) {
    node.visit(function (childNode) {
        childNode.select(isSelected);
    });
},
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top