- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
用户应该在选择一些组之后选择主机。我用 JQuery chained remote Plugin 构建了一个链式选择通过组选择主机。正在使用以下代码并且工作正常:
$('#hosts').remoteChained({
parents: "#hosts_group",
url: "ajax/getHosts"
});
<select id="hosts_group" name="hosts_group" class="form-control">
<option value="">Bitte Gruppe selektieren</option>
<option value="1>Some Groups</option>
</select>
<select id="hosts" name="hosts"></select>
但最终结果应该为主机提供一个双列表框,用户可以在其中从任何组中选择主机。我尝试将多个标签添加到主机选择并添加 JQuery DuallistBox通过以下代码段:
$('#hosts').remoteChained({
parents: "#hosts_group",
url: "ajax/getHosts"
}).DualListBox({json: false});
双列表框显示正常,但当我选择组时没有显示主机。
JSON 数据如下所示:
[
{'name': 'host1', 'id': '1'},
{'name': 'host2', 'id': '2'}
]
选择不同的组时,json 还包含不同的主机。链式选择插件通过以下请求请求数据:ajax/getHosts/?hosts_group=selectedId
只需将链式选择与普通的多重选择结合使用就可以了。问题是在双列表框中显示 json 数据,每次选择都不同。
我尝试构建一个 JsFiddle 示例,但它不起作用,因为不会加载外部库,而且我真的不明白如何通过不同的选择手动提供 json。
最佳答案
好的,我想我已经按照您想要的方式工作了。问题源于 DualListBox 试图在 remoteChained 完成填充选择框之前初始化自身。理想的解决方案是在 remoteChained 完成时,初始化 DualListBox。不幸的是,remoteChained 似乎没有回调函数,这使得这有点棘手。这是我的(有点老套)解决方案:
$(document).ready(function() {
// setup remote chained
$('#hosts').remoteChained({
parents: "#hosts_group",
url: "ajax/getHosts"
});
// set up dualList when change is triggered
$('#hosts_group').on("change", function() {
// if the option wasn't the first one
if($(this).find("option:selected").val() != "") {
setUpDualList();
} else {
// left as an exercise
//putHostsSelectBoxBackIfItWasDestroyedByDualList();
}
});
});
function setUpDualList() {
if(!hostsChanged()) {
// because there's no callback, we have continually check if json is complete
setTimeout(function() { setUpDualList(); }, 300);
} else {
// this actually does it.
$("#hosts").DualListBox({json:false});
}
}
function hostsChanged() {
/*
* this is VERY simplistic. It will have to handle if #hosts was
* 'changed' to have the same content, or if it was changed to
* something that has the same number of options, etc. This ONLY
* works for the very simple case you presented above.
*/
return $("#hosts").find("option").length != 0;
}
HTML 可以保持不变:
<select id="hosts_group" name="hosts_group" class="form-control">
<option value="">Bitte Gruppe selektieren</option>
<option value="1">Some Groups</option>
</select>
<select id="hosts" name="hosts"></select>
但是,由于 DualListBox 具有破坏性,因此最好创建一个“hosts”选择和一个“hosts_destroyable”选择。可破坏的选择将简单地复制 ajax complete 上的“hosts”,初始化 DualList,并隐藏“hosts”。当需要再次隐藏 DualList 时(因为用户更改了选择的组),则需要重新创建“hosts_destroyable”。
所以。上面是简短的、hacky 的、是的,这是可行的,但它需要帮助的解决方案。下面是一个逐步的完整解决方案。
初始化远程链接
将#hosts_group 更改为有效组:
$("#hosts").show();
监控#hosts 并确定 remoteChained 何时成功完成 json 请求。
请求完成后,将#hosts 复制到临时#hosts_temp
$("#hosts_temp").DualListBox({json:false})
$("#hosts").hide();
关于将#hosts_group 更改为无效组(例如“Bitte Gruppe selektieren”):
销毁 DualListBox(不确定创建的是什么,如果存在,则以某种方式从 DOM 中删除)
$("#hosts").show();
关于javascript - JQuery 在链式选择后选择多个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31003603/
是否有某种方法可以使用 JPA 或 Hibernate Crtiteria API 来表示这种 SQL?或者我应该将其作为 native 执行吗? SELECT A.X FROM (SELECT X,
在查询中, select id,name,feature,marks from (....) 我想删除其 id 在另一个 select 语句中存在的那些。 从 (...) 中选择 id 我是 sql
我想响应用户在 select 元素中选择一个项目。然而这个 jQuery: $('#platypusDropDown').select(function () { alert('You sel
这个问题在这里已经有了答案: SQL select only rows with max value on a column [duplicate] (27 个回答) 关闭8年前。 我正在学习 SQL
This question already has answers here: “Notice: Undefined variable”, “Notice: Undefined index”, and
我在 php 脚本中调用 SQL。有时“DE”中没有值,如果是这种情况我想从“EN”中获取值 应该是这样的,但不是这样的 IF (EXISTS (SELECT epf_application_deta
这可能是一个奇怪的问题,但不知道如何研究它。执行以下查询时: SELECT Foo.col1, Foo.col2, Foo.col3 FROM Foo INNER JOIN Bar ON
如何在使用 Camera.DestinationType.FILE_URI. 时在 phonegap camera API 中同时选择或拾取多个图像我能够一次只选择一张图像。我可以使用 this 在
这是一个纯粹的学术问题。这两个陈述实际上是否相同? IF EXISTS (SELECT TOP 1 1 FROM Table1) SELECT 1 ELSE SELECT 0 相对 IF EXIS
我使用 JSoup 来解析 HTML 响应。我有多个 Div 标签。我必须根据 ID 选择 Div 标签。 我的伪代码是这样的 Document divTag = Jsoup.connect(link
我正在处理一个具有多个选择框的表单。当用户从 selectbox1 中选择一个选项时,我需要 selectbox2 active 的另一个值。同样,当他选择 selectbox2 的另一个值时,我需要
Acme Inc. Christa Woods Charlotte Freeman Jeffrey Walton Ella Hubbard Se
我有一个login.html其中form定义如下: First Initial Plus Last Name : 我的do_authorize如下: "; pri
$.get( 'http://www.ufilme.ro/api/load/maron_online/470', function(data
我有一个下拉列表“磅”、“克”、“千克”和“盎司”。我想要这样一种情况,当我选择 gram 来执行一个函数时,当我在输入字段中输入一个值时,当我选择 pounds 时,我想要另一个函数来执行时我在输入
我有一个 GLSL 着色器,它从输入纹理的 channel 之一(例如 R)读取,然后写入输出纹理中的同一 channel 。该 channel 必须由用户选择。 我现在能想到的就是使用一个 int
我想根据下拉列表中的选定值生成输入文本框。 Options 2 3 4 5 就在这个选择框之后,一些输入字段应该按照选定的数字出现。 最佳答案 我建议您使用响应式(Reac
我是 SQL 新手,我想问一下如何根据首选项和分组选择条目。 +----------+----------+------+ | ENTRY_ID | ROUTE_ID | TYPE | +------
我有以下表结构: CREATE TABLE [dbo].[UTS_USERCLIENT_MAPPING_USER_LIST] ( [MAPPING_ID] [int] IDENTITY(1,1
我在移除不必要的床单时遇到了问题。我查看了不同的论坛并将不同的解决方案混合在一起。 此宏删除工作表(第一张工作表除外)。 Sub wrong() Dim sht As Object Applicati
我是一名优秀的程序员,十分优秀!