JavaScript中的ruby提供了未捕获的SyntaxError:意外标识符

JavaScript中的ruby提供了未捕获的SyntaxError:意外标识符,javascript,jquery,ruby-on-rails,ruby,Javascript,Jquery,Ruby On Rails,Ruby,我正在构建presentation builder,并试图将参数中的数据写入JavaScript对象$(“#数据存储”)。 一切进展顺利,但@content出现了问题。它包含一张幻灯片的html。当我尝试使用parent.$(“#数据存储”).data(“content[]”,“”);在控制台中未捕获SyntaxError:出现意外标识符 var fillUpData = function() { if ( $.isEmptyObject(parent.$("#data-sto

我正在构建presentation builder,并试图将参数中的数据写入JavaScript对象$(“#数据存储”)。 一切进展顺利,但@content出现了问题。它包含一张幻灯片的html。当我尝试使用parent.$(“#数据存储”).data(“content[]”,“”);在控制台中未捕获SyntaxError:出现意外标识符

  var fillUpData = function() {
       if ( $.isEmptyObject(parent.$("#data-store").data())) {
         console.log("empty")
         parent.$("#data-store").data("wallpaper", "<%= @wallpaper %>" );
         parent.$("#data-store").data("imageNum", "<%= @imageNum %>" );
          <% @num_slides.times do |n| %> 
         parent.$("#data-store").data("background[<%=n%>]", "<%= @background[n.to_s] %>" );
         parent.$("#data-store").data("content[<%=n%>]", "<%= @content[n.to_s].html_safe %>" );
          <% end %>
         // parent.$("#data-store").data("data", [<%= @datastore.html_safe %>]);
          } else {
        console.log("notempty");
        }
      }
var fillupdatea=function(){
if($.isEmptyObject(父项.$(“#数据存储”).data()){
console.log(“空”)
父项。$(“#数据存储”).data(“墙纸”,“壁纸”);
父项。$(“#数据存储”).data(“imageNum”,“数据”);
父项。$(“#数据存储”).data(“背景[]”,“”);
父项。$(“#数据存储”).data(“内容[]”,“”);
//父项。$(“#数据存储”).data(“数据”,[]);
}否则{
console.log(“notempty”);
}
}
我认为@content中的数据结构可能有问题。 @content的参数看起来像:

"content"=>{"0"=>"<img id=\"link2\" style=\"position: absolute\" src=\"http://i.imgur.com/X0XCFys.png \"><div class=\"editor\" contenteditable=\"true\" style=\"position: absolute; left: 743px; top: 312px;\"><h2 class=\"text2\">Title</h2></div><div class=\"ui-wrapper ui-draggable\" style=\"overflow: hidden; position: absolute; width: 128px; height: 128px; top: 225.1111125946045px; left: 508.1111145019531px; margin: 0px;\"><img id=\"link1\" style=\"position: static; margin: 0px; resize: none; zoom: 1; display: block; height: 128px; width: 128px;\" src=\"http://i.imgur.com/qTXDZhT.png \" class=\"ui-resizable\"><div class=\"ui-resizable-handle ui-resizable-e\" style=\"z-index: 90;\"></div><div class=\"ui-resizable-handle ui-resizable-s\" style=\"z-index: 90;\"></div><div class=\"ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se\" style=\"z-index: 90;\"></div><img class=\"icon-layer-up icon-on-img\" src=\"/assets/icon_layer_up.png\" style=\"z-index: 2;\"><img class=\"icon-layer-down icon-on-img\" src=\"/assets/icon_layer_down.png\" style=\"z-index: 2;\"><img class=\"icon-trash1 icon-on-img\" src=\"/assets/icon_trash.png\" style=\"z-index: 2;\"><img class=\"icon-copy-el icon-on-img\" src=\"/assets/icon_copy.png\" style=\"z-index: 2;\"><img class=\"icon-layer-up icon-on-img\" src=\"/assets/icon_layer_up.png\" style=\"z-index: 2;\"><img class=\"icon-layer-down icon-on-img\" src=\"/assets/icon_layer_down.png\" style=\"z-index: 2;\"><img class=\"icon-trash1 icon-on-img\" src=\"/assets/icon_trash.png\" style=\"z-index: 2;\"><img class=\"icon-copy-el icon-on-img\" src=\"/assets/icon_copy.png\" style=\"z-index: 2;\"></div>\r\n                    \r\n         \r\n    \r\n        ", "1"=>"\r\n                    \r\n         \r\n    \r\n        ", "2"=>"\r\n                    \r\n         \r\n    \r\n        ", "3"=>"\r\n                    \r\n         \r\n    \r\n        ", "4"=>"\r\n                    \r\n         \r\n    \r\n        ", "5"=>"\r\n                    \r\n         \r\n    \r\n        ", "6"=>"\r\n                    \r\n         \r\n    \r\n        ", "7"=>"\r\n                    \r\n         \r\n    \r\n        "},
“content”=>{“0”=>“Title\r\n\r\n\r\n\r\n”、“1”=>“\r\n\r\n\r\n”、“2”=>“\r\n\r\n\r\n”、“3”=>“\r\n\r\n\r\n\r\n\r\n”、“4”=>“\r\n\r\n\r\n\r\n”,“5”=>“\r\n\r\n\r\n\r\n”,“6”=>“\r\n\r\n\r\n\r\n”,“7”=>“\r\n\r\n\r\n”},
当我在控制台中检查此功能时,我得到如下结果:

 var fillUpData = function() {
   if ( $.isEmptyObject(parent.$("#data-store").data())) {
     console.log("empty")
     parent.$("#data-store").data("wallpaper", "http://i.imgur.com/cRrY9Fk.png" );
     parent.$("#data-store").data("text", "" );
     parent.$("#data-store").data("imageNum", "1" );
     parent.$("#data-store").data("background[0]", "url(http://i.imgur.com/nYkdOne.png)" );
     parent.$("#data-store").data("content[0]", "<div class="editor ui-resizable ui-draggable" contenteditable="true" style="position: absolute; left: 298.1111602783203px; top: 193.09722900390625px;"><h2 class="text2">Titsadasdle</h2><div class="ui-resizable-handle ui-resizable-e" style="z-index: 90;"></div><div class="ui-resizable-handle ui-resizable-s" style="z-index: 90;"></div><div class="ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se" style="z-index: 90;"></div><img class="icon-layer-up2 icon-on-edit" src="/assets/icon_layer_up.png" style="z-index: 2;"><img class="icon-layer-down2 icon-on-edit" src="/assets/icon_layer_down.png" style="z-index: 2;"><img class="icon-trash2 icon-on-edit" src="/assets/icon_trash.png" style="z-index: 2;"><i class="icon-move icon-on-edit" style="z-index: 2;"></i><i class="icon-font font2 icon-on-edit" style="z-index: 2;"></i><img class="icon-font-size icon-on-edit" src="/assets/font_size2.png" style="z-index: 2;"></div><div class="ui-wrapper ui-draggable" style="overflow: hidden; position: absolute; width: 128px; height: 128px; top: 285.1111125946045px; left: 52.111114501953125px; margin: 0px;"><img id="link1" style="position: static; margin: 0px; resize: none; zoom: 1; display: block; height: 128px; width: 128px;" src="http://i.imgur.com/qTXDZhT.png " class="ui-resizable"><div class="ui-resizable-handle ui-resizable-e" style="z-index: 90;"></div><div class="ui-resizable-handle ui-resizable-s" style="z-index: 90;"></div><div class="ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se" style="z-index: 90;"></div><img class="icon-layer-up icon-on-img" src="/assets/icon_layer_up.png" style="z-index: 2;"><img class="icon-layer-down icon-on-img" src="/assets/icon_layer_down.png" style="z-index: 2;"><img class="icon-trash1 icon-on-img" src="/assets/icon_trash.png" style="z-index: 2;"><img class="icon-copy-el icon-on-img" src="/assets/icon_copy.png" style="z-index: 2;"><img class="icon-layer-up icon-on-img" src="/assets/icon_layer_up.png" style="z-index: 2;"><img class="icon-layer-down icon-on-img" src="/assets/icon_layer_down.png" style="z-index: 2;"><img class="icon-trash1 icon-on-img" src="/assets/icon_trash.png" style="z-index: 2;"><img class="icon-copy-el icon-on-img" src="/assets/icon_copy.png" style="z-index: 2;"></div>



    " );
     parent.$("#data-store").data("background[1]", "url(http://i.imgur.com/zXJv24z.png)" );
     parent.$("#data-store").data("content[1]", "



    " );
     parent.$("#data-store").data("background[2]", "" );
     parent.$("#data-store").data("content[2]", "



    " );
     parent.$("#data-store").data("background[3]", "" );
     parent.$("#data-store").data("content[3]", "



    " );
     parent.$("#data-store").data("background[4]", "" );
     parent.$("#data-store").data("content[4]", "



    " );
     parent.$("#data-store").data("background[5]", "" );
     parent.$("#data-store").data("content[5]", "



    " );
     parent.$("#data-store").data("background[6]", "" );
     parent.$("#data-store").data("content[6]", "



    " );
     parent.$("#data-store").data("background[7]", "" );
     parent.$("#data-store").data("content[7]", "



    " );
      } else {
    console.log("notempty");
    }
  }
var fillupdatea=function(){
if($.isEmptyObject(父项.$(“#数据存储”).data()){
console.log(“空”)
父项。$(“#数据存储”).data(“墙纸”http://i.imgur.com/cRrY9Fk.png" );
父项。$(“#数据存储”).data(“文本”,“文本”);
父项。$(“#数据存储”).data(“imageNum”,“1”);
父项。$(“#数据存储”).data(“背景[0],“url(http://i.imgur.com/nYkdOne.png)" );
父项。$(“#数据存储”).data(“内容[0]”,标题为
" );
父项。$(“#数据存储”).data(“背景[1],“url(http://i.imgur.com/zXJv24z.png)" );
父项。$(“#数据存储”).data(“内容[1]”,”
" );
父项。$(“#数据存储”).data(“背景[2],”);
父项。$(“#数据存储”).data(“内容[2]”,“
" );
父项。$(“#数据存储”).data(“背景[3],”);
父项。$(“#数据存储”).data(“内容[3],”
" );
父项。$(“#数据存储”).data(“背景[4],”);
父项。$(“#数据存储”).data(“内容[4]”,”
" );
父项。$(“#数据存储”).data(“背景[5],”);
父项。$(“#数据存储”).data(“内容[5],”
" );
父项。$(“#数据存储”).data(“背景[6],”);
父项。$(“#数据存储”).data(“内容[6]”,“
" );
父项。$(“#数据存储”).data(“背景[7],”);
父项。$(“#数据存储”).data(“内容[7]”,”
" );
}否则{
console.log(“notempty”);
}
}

如何才能将每个内容的参数写入JavaScript object data()?

生成的HTML有一个问题:

parent.$(“#数据存储”).data(“内容[0],“Titsadasdle”)
//^等等。
有一些未替换的引用正在使用中。在这里调用
.html\u safe
是不够的;您需要运行一段代码来将
替换为
\”
。幸运的是,这是一项简单的任务:

tmp=@content[n.to\s].html\u安全
开始
#正则表达式匹配前面没有反斜杠的双引号
tmp[/(?标题栏”)

您可以使用类似的策略来逃避JavaScript可能抱怨的任何其他内容。

您生成的HTML有一个问题:

parent.$(“#数据存储”).data(“内容[0],“Titsadasdle”)
//^等等。
有一些未替换的引用正在使用中。在这里调用
.html\u safe
是不够的;您需要运行一段代码来将
替换为
\”
。幸运的是,这是一项简单的任务:

tmp=@content[n.to\s].html\u安全
开始
#正则表达式匹配前面没有反斜杠的双引号
tmp[/(?标题栏”)

您可以使用类似的策略来逃避JavaScript可能抱怨的任何其他内容。

您生成的HTML有一个问题:

parent.$(“#数据存储”).data(“内容[0],“Titsadasdle”)
//^等等。
有一些未替换的引用正在使用中。在这里调用
.html\u safe
是不够的;您需要运行一段代码来将
替换为
\”
。幸运的是,这是一项简单的任务:

tmp=@content[n.to\s].html\u安全
开始
#正则表达式匹配前面没有反斜杠的双引号
tmp[/(?标题栏”)

您可以使用类似的策略来逃避JavaScript可能抱怨的任何其他内容。

您生成的HTML有一个问题:

parent.$(“#数据存储”).data(“内容[0],“Titsadasdle”)
//^等等。
有一些未替换的引用正在使用中。在这里调用
.html\u safe
是不够的;您需要运行一段代码来将
替换为
\”
。幸运的是,这是一项简单的任务:

tmp=@content[n.to\s].html\u安全
开始
#正则表达式匹配前面没有反斜杠的双引号
tmp[/(?标题栏”)

您可以使用类似的策略来逃避JavaScript可能会抱怨的任何其他内容。

查看生成的HTML。查看生成的HTML。查看生成的HTML。查看生成的HTML。当我尝试这样做时,出现了错误regexp不匹配:parent。$(“#