在我的rails应用程序中,我试图在application.js脚本中调用document.ready函数来自动完成。在重新加载file.ie时调用此函数两次即使我不包含= javascript_include_tag:defaults ,:cache =>如果它被称为两次,它就被称为一次。因此,我传递的值被替换为null。任何想法为什么它被调用两次?
%td.grid.full_panels
-table_panel "Assign Testers" do
%table
%th Name
-puts "testers=#{@testers}"
= 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
-@names=["sramya","scharron"]
:javascript
var data='#{escape_javascript @names.to_json.html_safe}'
= javascript_include_tag :defaults,:cache =>
我的application.js文件:
$(document).ready(function() {
console.log("inside application");
data1='["sramya","scharron"]';
console.log("before parsing"+data+",data1="+data1);
data=$.parseJSON(data);
data1=$.parseJSON(data1);
//console.log(data1);
console.log("after parsing"+data+",data1="+data1);
$('#release_tester_tokens').autocomplete({source:data1});
});
答案 0 :(得分:0)
有时候,萤火虫可能会发起DOM就绪事件,例如双重跟踪网。试着转动萤火虫