2011-08-26 33 views
0

我正在使用jstree並試圖捕獲複選框狀態更改事件。我如何獲取當前選中的複選框的狀態和其列表ID?如何捕獲複選框點擊事件?

我在這裏找到的例子: Jquery Jstree checkbox events capture 工作,但我無法弄清楚如何獲得節點的檢查狀態。如果有更好或更簡單的方法,我願意接受其他建議。

$("#demo1").bind("change_state.jstree", function (e, d) { 
     if ((d.args[0].tagName == "A" || d.args[0].tagName == "INS") && 
      (d.inst.data.core.refreshing != true && d.inst.data.core.refreshing != "undefined")) 
     { 
      //if a checkbox or it's text was clicked, 
      //and this is not due to a refresh or initial load, run this code . . . 
      alert("list id: " +d.rslt.attr("id")); 
      alert("is item checked?" +"***TODO***"); 
     } 
    }); 

謝謝。

**編輯:我讓我的問題更清楚,以避免任何關於組合插件的混淆(這不是我正在做的)。我在jstree中啓用了樹形複選框。 **

+0

您是否找到了解決方案?我面臨同樣的問題。 plz幫助。 – Shibankar

回答

0

不是解決方案,解決方法! 我發現這個職位尋找一個解決類似的問題,各種場景播放後決定不使用

real_checkboxes

選項。相反,我添加了一系列我自己的隱藏複選框,並修改了您的腳本以設置隱藏框的已檢查狀態,然後將其發回到表單中的服務器(MVC3)。然後,我可以使用樹節點LI的ID來設置我的複選框的選中狀態。

if ((d.args[0].tagName == "A" || d.args[0].tagName == "INS") && 
     (d.inst.data.core.refreshing != true && d.inst.data.core.refreshing != "undefined")) { 
      //if a checkbox or it's text was clicked, 
      //and this is not due to a refresh or initial load, run this code . . . 
      var id = d.rslt.attr("id"); 
      var checked = $("#" + id + ".jstree-checked").length!=0; // use the length!=0 to get a bool of the checked status 
      $("#log").append("list id: " + id); 
      $("#log").append("is item checked ? " + checked); 
      $("#log").append("<br/>"); 


     }