将 sj:select 与 s:checkboxlist 一起使用

发布于 2024-12-13 10:52:34 字数 1553 浏览 6 评论 0原文

因此,由于不同的原因,我在尝试使用这两个元素中的任何一个时遇到了麻烦。首先,我将描述 s:checkboxlist 发生的情况。

sj:select 上的值更改时,我想在控制器上填充一个列表以在 s:checkboxlist 上使用,我是否必须使用 JavaScript?我最初的猜测是在 sj:select onchange="" 参数上调用 javascript 函数,然后在 javascript 函数上刷新 s:checkboxlist 以便它使用新的填充列表。

例如,如果我的 sj:select:

<s:url id="urlGetNewList"
    action="mycontroller!getNewList" />
<sj:select href="%{urlGetNewList}" id="myselect"
    onChangeTopics="reloadList"
    onCompleteTopics="reloadList"
    name="model.idType" list="types"
    listKey="idType" listValue="nameType"
    emptyOption="false" headerKey="-1"
    headerValue="select a value"
    formIds="frmMyForm" />

s:checkboxlist 上有类似的内容:

<s:checkboxlist name="arrayOfIds" list="idsType"
                listKey="id" listValue="name"
                theme="vertical-checkbox" />

那么我的 s:select 就会被填充从名为 types 的列表中,当 sj:select 上的值更改时,我会调用控制器上名为 getNewList 的函数,这将更改使用我的复选框列表的列表,但是如何刷新复选框列表。

您可以注意到我可以通过使用 sj:checkboxlist 来解决这个问题,我知道它有效,但是如果我这样做,那么当我尝试加载通过整数数组 idsType 检查的复选框时,复选框不会被选中。例如,如果我有一个像这样的整数数组:

idsType = { 2, 3 }

并且我有一个包含 5 个元素的列表 arrayOfIds ,那么当我使用 s:checkboxlist 时,将显示 5 个复选框,并且将选中第二个和第三个复选框。

但是,如果我使用 sj:checkboxlist 执行此操作,则只会选中第一个复选框,并且复选框将根据 sj:select 值动态更改,这将不会'当我使用 s:checkboxlist 时,不会发生这种情况。

我真的不知道如何解决这个问题,如果有人可以提供帮助,我将非常感激。

So I have trouble trying to use any of these two elements for different reasons. First I'll describe what happens with the s:checkboxlist.

When the value on the sj:select changes I want to populate a list on my controller to use on my s:checkboxlist, do I have to use javascript? My initial guess was to call a javascript function on the sj:select onchange="" parameter, then on the javascript function refresh the s:checkboxlist so it populates using the new list.

For example if I have something like on my sj:select:

<s:url id="urlGetNewList"
    action="mycontroller!getNewList" />
<sj:select href="%{urlGetNewList}" id="myselect"
    onChangeTopics="reloadList"
    onCompleteTopics="reloadList"
    name="model.idType" list="types"
    listKey="idType" listValue="nameType"
    emptyOption="false" headerKey="-1"
    headerValue="select a value"
    formIds="frmMyForm" />

and on my s:checkboxlist I have :

<s:checkboxlist name="arrayOfIds" list="idsType"
                listKey="id" listValue="name"
                theme="vertical-checkbox" />

So my s:select gets populated from a list called types, when the value on the sj:select changes I call a function on my controller named getNewList, that will change the list that uses my checkboxlist, but how can refresh the checkboxlist.

You can notice I could solve this by using a sj:checkboxlist, I know it works, but if I do that then when I try to load the checkbox that are checked through the Integer array idsType, the checkboxes won't get checked. For example if I have an Integer array like this:

idsType = { 2, 3 }

and I have a list arrayOfIds with 5 elements, then when I use the s:checkboxlist, 5 checkboxes will be shown and the second and third checkbox will be checked.

But if I do this using sj:checkboxlist, then only the first checkbox will be checked and also the checkboxes will change dinamically according to the sj:select value, which won't happen when I use a s:checkboxlist.

I'm really lost as to how can I solve this issue, if anybody can help it will be very much appreciated.

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

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

发布评论

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

评论(1

不语却知心 2024-12-20 10:52:34

要回答第一个问题,您当然需要使用 JavaScript 来更新复选框列表 - 标准 完全不支持 Ajax。您需要通过绑定到 sj:select 发布的主题来手动执行此操作。

插件 wiki(假设这是您正在使用的插件,实际上有一些)有一个页面讨论 如何处理主题中的 JSON 结果

可以通过监听主题来重新加载;处理列表中的多个项目应该没有问题;您可能需要提供有关您尝试过的操作以及出现的问题的其他详细信息(例如,如果有任何问题,请检查 JavaScript 控制台)。

To answer the first question, of course you'd need to use JavaScript to update the checkbox list--the standard <s:checkboxlist> is completely unaware of Ajax. You would need to do it manually by binding to the topic published by the sj:select.

The plugin wiki (assuming this is the plugin you're using, there are actually a few) has a page discussing how to handle JSON results in a topic.

The <sj:checkboxlist> can reload by listening to topics; there should be no issue handling multiple items in the list; you may need to provide additional details regarding what you tried, and what went wrong (if anything, for example, check the JavaScript console).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文