在表单中使用 jstree 复选框

发布于 2024-11-09 22:26:36 字数 1500 浏览 4 评论 0原文

抱歉,标题有点含糊。我的问题非常具体(可能只是我是新手),我只是不知道如何在标题中解释它。

我目前正在升级一个网页。该网页有 3 个列表,其中包含项目,例如“设备”列表有不同类型的汽车。每个项目都有一个复选框,用户选中他想要使用的项目,然后按下按钮。然后他会收到一份基于他的选择的报告。

<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" />" />

这是按钮的代码。

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);
              }

这是用户按下按钮时触发的序列化函数的一部分。 $(".devicesCB:checked") 部分是 jQuery,并返回 "devicesCB" 类的所有选中复选框。这句话也是我问题的关键。

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

根据 jstree 文档,这应该创建在表单中工作的复选框。我有什么想法如何检索这些数据吗?我尝试过 var cb = $(".jstree-checkbox:checked") 它并没有真正做任何事情,我也尝试使用树的选择器 var AreasCB = $("#树”); 但我不知道如何处理它。

我很确定这是一个相当简单的问题,但总的来说我对 jQuery 和 javascript 仍然很陌生。

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, this 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

行至春深 2024-11-16 22:26:36

这是获取已检查节点的一种方法:

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

Here is one way of getting the checked nodes:

$("#my_tree").jstree("get_checked", null, false).each(function() {
    //do something
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文