简体   繁体   English

twitter bootstrap的预输入和多个文本字段

[英]twitter bootstrap's typeahead and multiple text fields

My app deals with Tags and Films entities: Many-to-Many relation. 我的应用程序处理“标签和电影”实体:多对多关系。 Joining entity is named as "tagazation". 加入实体被称为“ tagazation”。 I want user to be able to add tags to each film in modal window. 我希望用户能够在模态窗口中向每部电影添加标签。 So I render hidden modal window to page for each film in the index action. 因此,我为index动作中的每部影片渲染了隐藏的模态窗口到页面。 The problem is in tag_id field: I have twitter bootstrap's typeaheaded textfield in each forms. 问题出在tag_id字段中:我在每种表单中都有twitter bootstrap的typeaheaded文本字段。 All these fields share common class "tags-input". 所有这些字段共享通用类“标签输入”。 On select event in textfield fires the set_id function: 文本字段中的select事件触发set_id函数:

$(document).ready(function() {
function set_id(item, val, text){
    $(this).parent().children("#tagazation_tag_id").val(val);
}
$(".tags-input").typeahead({
    source: [],
    itemSelected: set_id
});
});

set_id function is supposed to change PARTICULAR hidden field in the same form as a textfield that fired that callback, but there are multiple hidden fields for tag id. set_id函数应该以与触发该回调的文本字段相同的形式来更改PARTICULAR隐藏字段,但是标记id有多个隐藏字段。 That of course wouldn't be a big problem if we knew for what film exactly that set_id function is fired up. 如果我们确切知道set_id函数是在哪部电影中启动的,那当然不是什么大问题。

I believe, that there is should be a "standart" way to cope with this propblem instead of my still-not-working browsing thru the DOM tree search. 我相信,应该有一种“标准的”方式来解决这个问题,而不是通过DOM树搜索仍然无法正常工作的浏览方式。

If I understand what you're trying to do, I think the easiest solution would be to render only one hidden modal dialog to html instead of one modal dialog for every movie. 如果我了解您要执行的操作,我认为最简单的解决方案是将仅一个隐藏的模式对话框呈现为html,而不是为每部电影都提供一个模式对话框。 Right before you open the modal, you can use javascript to set whatever text is needed to make the modal refer to the movie that was clicked. 在打开模态之前,您可以使用javascript设置所需的任何文本,以使模态引用被单击的电影。

If you only have one modal dialog, you can just refer to the hidden tag id field as $('#tagazation_tag_id') , with no confusion as to which input it refers to. 如果只有一个模式对话框,则可以将隐藏的标签ID字段称为$('#tagazation_tag_id') ,不要混淆它所引用的输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM