开发者

Using jstree checkboxes in forms

Sorry for the slightly ambiguous title. My problem is very specific (and it's probably just me being a newb), I just didn't know how to explain it in the title.

I'm currently upgrading a webpage. This webpage has 3 lists with items in them, for example the Devices list has different types of cars. Each item has a checkbox, the user checks the ones he wants to use, and then presses a button. Then he receives a report based on his selections.

<input type="button" class="mapbutton"  onclick="company.view.reports.serialize(this);" 
                style="width:280px;font-size:1em" 
                value="<fmt:message key="owner.text.open_report" />" />

This is the code for the button.

serialize: function(what){
              var m = company.model.report;
              var strDev = 'devices=';
              var devicesCB = $(".devicesCB:checked");
              if (devicesCB.length > 0){
                  for (var i=0;i<devicesCB.length;i++) {
                     strDev += devicesCB[i].value + ',';
                  }
                  strDev = strDev.substring(0, strDev.length - 1);
              }

and this is part of the serialize function that is fired when the user presses the button. The $(".devicesCB:checked") part is jQuery, and returns all the checked checkboxes of the class "devicesCB". This line is also the key to my question.

checkbox : {
        "real_checkboxes" : "true",
        "override_ui" : "true",
        "real_checkboxes_names" : function(n){
            console.log("As");
            return[("area"+n[0].id),n[0].id];
        }
    },

According to the jstree documentation, thi开发者_JAVA百科s should create checkboxes that work in forms. Any ideas how I would go about retrieving this data? I have tried var cb = $(".jstree-checkbox:checked") which didn't really do anything, also I tried working with the tree's selector var areasCB = $("#tree"); but I couldn't figure out what to do with it.

I'm pretty sure this is a fairly simple problem, but I'm still very new to jQuery and javascript in general.


Here is one way of getting the checked nodes:

$("#my_tree").jstree("get_checked", null, false).each(function() {
    //do something
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜