【发布时间】:2015-09-02 13:22:26
【问题描述】:
我有一个带有一些引导属性的标签,我想在按编辑链接时选择一个特定选项,但现在它不起作用,其他字段有效但选择始终获取默认选项。
选择
<div class="form-group">
<select id="categoryField" form="formPerson" class="form-control select2me" placeholder="Categoría" th:field="*{category}">
<option value="-1">Categoría</option>
<option th:each="cat : ${categorias}" th:value="${cat.id}" th:text="${cat.name}"></option>
</select>
</div>
脚本
function editJury(year, category, juryType, accepted, acceptDate, notes, index){
$('#categoryField option[value="'+category+'"]');
$('#yearField').val(year);
$('#juryTypeField').val(juryType);
$('#dateField').val(acceptDate);
if(accepted==1){
$('#radio6').val(accepted);
}
if(accepted==0){
$('#radio7').val(accepted);
}
if(accepted==null){
$('#radio8').val(accepted);
}
$('#notesField').val(notes);
$('#indexField').val(index);
}
我尝试了this 但对我不起作用,我认为这是因为当我检查最终的 html 引导程序转换时,div 中的 select 标记...
编辑:我完全改变了如何编辑它,现在我想最好不要使用这么多的 JQuery,所以现在我有两个问题,首先,我可以获得选定的值正确(始终保持默认值 -1)并且在页面加载时不会打开模式对话框。
现在,当你点击这个
<a class="edit" href="#modal-jury-form" th:href="@{/person/edit_jury/__${status.index}__}" data-toggle="modal">Editar </a>
启动控制器方法:
@RequestMapping(value = "person/edit_jury/{index}", method = RequestMethod.GET)
public String editJury(@PathVariable String index, @ModelAttribute("person") PersonForm personForm,
RedirectAttributes ra, Model model) {
Jury jury = personForm.getJuries().get(Integer.parseInt(index));
personForm.setJuryAux(new JuryForm(jury));
model.addAttribute("person", personForm);
return "person/new";
}
然后返回页面,但模态不会自动加载...但是如果单击“新建”按钮,模态会加载我传递的数据,但加载默认选项的标签除外。
【问题讨论】:
-
$('#categoryField option[value="'+SEL1+'"]');行什么都不做 - 你希望它做什么? -
我错了,对不起
-
它不是我所指的
SEL1,而是整行——在你编辑后它仍然没有任何作用——再一次,那行应该做什么? -
如果您输入我在问题中所说的链接,您可以看到该问题的正确答案,其中一个解决方案是这个
-
YOU 是否真的阅读了您链接的答案-他们提供了要使用的选择器示例,选择器本身不做任何事情(选择元素除外)-您需要在某处调用方法!我已经多次尝试通过要求澄清来帮助你,你似乎对帮助自己没有兴趣,所以我不再打扰了。
标签: twitter-bootstrap spring-mvc jquery-select2 thymeleaf