如何以编程方式设置 jQuery 下拉检查列表的值?
如何以编程方式将某些复选框设置为选中状态?
场景如下: 一旦我通过管理屏幕创建用户,我就会有几个 jqueryDropdown 复选框,一个用于“用户角色”,一个用于“用户区域”,因为用户可以拥有与他/她关联的多个角色和多个区域。没问题,我已经完成并保存到数据库中。 我还为用户提供了更新用户角色和区域的能力,并且我想通过 jQuery 下拉检查列表来完成此操作,因此我的方法如下:
- 为他们提供用于创建用户的相同屏幕
- 发出 Ajax 请求获取用户特定的角色和区域。
- 现在我想做的是基于 Ajax 响应集,通过 DOM 脚本检查与响应值匹配的复选框。有人知道该怎么做吗?
How can I programatically set some checkboxes to selected?
The scenario is as follows:
Once I create a user through the admin screen I have a couple of jqueryDropdown checkboxes one for "User Roles" and one for "User Regions" since a user can have many roles and many regions associated with him/her. No problem there I got that accomplished and saved to the database.
I also give the user the ability to update the user roles and regions and I want to do it through the jQuery dropdown-check-list so my approach is as follows:
- Give them the same screen they used to create the user
- Issue an Ajax request to get the user specific roles and regions.
- Now what I want to do is based on the Ajax response set to checked the checkboxes that match the value of the response through DOM Scripting. Does anybody know how to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我已经找到了我自己问题的答案。首先我想提一下,我想填充这个 jquery 组件 http: //dropdown-check-list.googlecode.com/svn/trunk/doc/dropdownchecklist.html 如果我原来的问题有误导性,我们深表歉意。
填充我的 jquery 下拉清单插件的 Javascript 如下:
返回 JSON 的 grails 操作如下
I have found the answer to my own problem. First I want to mention that I wanted to populate this jquery component http://dropdown-check-list.googlecode.com/svn/trunk/doc/dropdownchecklist.html sorry if my original question was missleading.
The Javascript to populate my jquery drop down checklist plugin is as follows:
My grails action that returns JSON is as Follows
我创建了一个类结构,其中一般创建了 DDCL,并且代码:
破坏了最初创建的 DDCL 的完整性。
我发现这个解决方案更适合我的应用程序:
其中“值”是值数组(例如 [1, 2, 3])。这不会破坏最初创建的 DDCL 的完整性。
I've created a class structure, where a DDCL is created generically and the code:
destroys the integrity of the DDCL that was initially created.
I found that this solution works much better for my application:
where 'values' is an array of values (e.g. [1, 2, 3]). This does not destroy the integrity of the DDCL initially created.
返回一些带有状态的 JSON...
然后一些 jQuery 应该做到这一点...
Return some JSON with the state...
Then some jQuery should do it...