意外的“;空”;使用jquery令牌输入时的令牌字段-我如何摆脱它

Unexpected "null" token field when using jquery token input - how do I get rid of it?

本文关键字:令牌 字段 何摆脱 输入 使用 jquery 意外      更新时间:2023-09-26

我遵循了这个屏幕广播:http://railscasts.com/episodes/258-token-fields?view=asciicast

作为其中一个步骤,我按照建议添加了预填充选项,并使编辑表单运行良好。这是用coffeescript编写的javascript,因为我使用的是Rails3.1:

  $("#location_token_field").tokenInput "/person/locations.json", {
    crossDomain: false,
    prePopulate: $(this).data("pre"),
    theme: "facebook",
    preventDuplicates: true
  }

这一切都很好,除了现在,在#new操作中,令牌输入字段总是以"null"开头

以下是有问题的表单部分:

    <div id="location_area">
        <%= link_to image_tag("location_icon2.png", :size=>"35x35"), "javascript:void(0)", id: "location_icon", class: "blank_button" %>
        <div id="location_field">
            <%= f.text_field :location_tokens, id: "location_token_field", placeholder: "Where?", 
                "data-pre" => memory.locations.map(&:attributes).to_json %>
        </div>
    </div>

有什么想法吗?为什么会发生这种情况/我该如何解决?我希望保持预填充,以便适当地填充编辑表单。

仅仅从查看JavaScript的角度来看,似乎缺少了一些括号:

尝试:

 $("#location_token_field").tokenInput("/person/locations.json", {
    crossDomain: false,
    prePopulate: $(this).data("pre"),
    theme: "facebook",
    preventDuplicates: true
  });

看看这是否有帮助。