jquery 自动完成插件中的数据未解析为 json
我想在 Rails 应用程序中实现自动完成功能。我正在使用 jquery 自动完成插件。
我想为以下数组实现自动完成功能。
@testers = User.find_by_sql("select * from users where id in(select user_id from user_role_assignments where role_id in (select id from roles where name like 'Tester')) order by name").paginate(:page=>params[:page],:per_page=>30)
我想将其以 json 格式传递到 .js 文件。我尝试在视图文件中使用以下代码。但是自动完成不会填充数据。
= form.label :tester_tokens, "Testers"
= form.text_field :tester_tokens
- @testers.each do |tester|
%tr
%td=tester.name
%td=check_box_tag "release[tester_ids][]", tester.id, @release.is_tester_assigned(tester)
//=will_paginate @testers
:javascript
var data="#{escape_javascript @testers.to_json}";
= javascript_include_tag :defaults,:cache => true
我的 .js 文件:
$(document).ready(function() {
$.parseJSON(data);
alert (data);
$('#release_tester_tokens').autocomplete({source:data});
});
请帮助我。
I want to implement auto complete feature in a rails application. I am using the jquery auto complete plugin.
I want to implement the auto complete feature for the following array.
@testers = User.find_by_sql("select * from users where id in(select user_id from user_role_assignments where role_id in (select id from roles where name like 'Tester')) order by name").paginate(:page=>params[:page],:per_page=>30)
I want to pass this in json format to the .js file. I tried using the below code code in my view file.But the auto complete is not populating the data.
= form.label :tester_tokens, "Testers"
= form.text_field :tester_tokens
- @testers.each do |tester|
%tr
%td=tester.name
%td=check_box_tag "release[tester_ids][]", tester.id, @release.is_tester_assigned(tester)
//=will_paginate @testers
:javascript
var data="#{escape_javascript @testers.to_json}";
= javascript_include_tag :defaults,:cache => true
My .js file:
$(document).ready(function() {
$.parseJSON(data);
alert (data);
$('#release_tester_tokens').autocomplete({source:data});
});
Please help me out here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将丢弃
$.parseJSON
返回的值。You're discarding the value returned by
$.parseJSON
.