Jquery tokenInput 未预填充 text_field
您好,我有 tokenInput 文档,但不知何故,我的文本字段category_tokens 在编辑时没有预先填充类别。
这是代码片段
<input id="product_category_tokens" type="text" size="30" name="product[category_tokens]" data-pre="[{"created_at":"2010-09-13T03:33:17Z","description":"","id":x,"name":"Kitchen & Dining ","parent_id":xx,"permalink":"kitchen-dining","updated_at":"2011-01-05T11:17:10Z"}]" style="display: none;">
$(function() {
$("#product_category_tokens").tokenInput("/categories.json", {
crossDomain: false,
prePopulate: $('#product_category_tokens').data('pre'),
preventDuplicates: true
});
});
<%= f.text_field :category_tokens, "data-pre" => @product.categories.map(&:attributes).to_json %>
任何指针表示赞赏!
Hi I've tokenInput documentation but somehow my text_field category_tokens is not prepopulated with categories while editing.
Here are code snippets
<input id="product_category_tokens" type="text" size="30" name="product[category_tokens]" data-pre="[{"created_at":"2010-09-13T03:33:17Z","description":"","id":x,"name":"Kitchen & Dining ","parent_id":xx,"permalink":"kitchen-dining","updated_at":"2011-01-05T11:17:10Z"}]" style="display: none;">
$(function() {
$("#product_category_tokens").tokenInput("/categories.json", {
crossDomain: false,
prePopulate: $('#product_category_tokens').data('pre'),
preventDuplicates: true
});
});
<%= f.text_field :category_tokens, "data-pre" => @product.categories.map(&:attributes).to_json %>
Any pointer is appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
评论(3)
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
也许您可以尝试将
prePopulate
更改为$(this).data("pre")
。另一个技巧是在 JS 函数和视图中使用字段类而不是 id,因为它在渲染时会发生变化。
希望对您有帮助。
Maybe you can try to change your
prePopulate
to$(this).data("pre")
.Another tip is to use field class instead of id in the JS function and in your view since it changes when rendered.
Hope it help you.