打开 Flash Chart 2 - ID 相同,因此不显示倍数

发布于 2024-09-26 14:35:41 字数 1358 浏览 5 评论 0原文

我每次观看都可以获得一张成功的 Open Flash Chart。 我现在尝试支持每个视图多个打开的 Flash 图表,但源代码显示两个生成的 div 的 id 相同:

# javascript at top of view
<%= javascript_include_tag "swfobject.js", :cache => true %>

# view itself
<%= @graph.html_safe %>  # html_safe is necessary for Rails 3
<%= @graph2.html_safe %>

# view's source code
<div id='flashcontent_913000'></div> 
  <script type="text/javascript"> 
    swfobject.embedSWF(
    "/open-flash-chart.swf","flashcontent_913000",
    "440", "310", "9.0.0", "expressInstall.swf",
    {"data-file":"/analytics%2Fpie1"}, {}, {} );
  </script> 
</div> 
<br /> 

<div id='flashcontent_913000'></div> 
  <script type="text/javascript"> 
    swfobject.embedSWF(
    "/open-flash-chart.swf","flashcontent_913000",
    "440", "310", "9.0.0", "expressInstall.swf",
    {"data-file":"/analytics%2Fpie2"}, {}, {} );
  </script> 
</div>

#controller
respond_to do |wants|
  wants.html {
    @graph = ofc2( 440, 310, 'analytics/pie1' )
    @graph2 = ofc2( 440, 310, 'analytics/pie2' )
  }
end
def pie1
... # functioning when put in the view alone
end
def pie2
... # functioning when put in the view alone
end

因为 id 相同,所以 <%= @graph.html_safe %>; 尝试渲染 graph2 但失败,并且 graph2 根本不显示。我需要让 OFC2 生成不同的 id。我怎样才能做到这一点?

I can get one successful Open Flash Chart per view.
I'm now trying to support multiple Open Flash Charts per view but the source code shows that the ids for both generated divs are the same:

# javascript at top of view
<%= javascript_include_tag "swfobject.js", :cache => true %>

# view itself
<%= @graph.html_safe %>  # html_safe is necessary for Rails 3
<%= @graph2.html_safe %>

# view's source code
<div id='flashcontent_913000'></div> 
  <script type="text/javascript"> 
    swfobject.embedSWF(
    "/open-flash-chart.swf","flashcontent_913000",
    "440", "310", "9.0.0", "expressInstall.swf",
    {"data-file":"/analytics%2Fpie1"}, {}, {} );
  </script> 
</div> 
<br /> 

<div id='flashcontent_913000'></div> 
  <script type="text/javascript"> 
    swfobject.embedSWF(
    "/open-flash-chart.swf","flashcontent_913000",
    "440", "310", "9.0.0", "expressInstall.swf",
    {"data-file":"/analytics%2Fpie2"}, {}, {} );
  </script> 
</div>

#controller
respond_to do |wants|
  wants.html {
    @graph = ofc2( 440, 310, 'analytics/pie1' )
    @graph2 = ofc2( 440, 310, 'analytics/pie2' )
  }
end
def pie1
... # functioning when put in the view alone
end
def pie2
... # functioning when put in the view alone
end

Because the ids are the same, <%= @graph.html_safe %> tries to render graph2 and fails, and graph2 doesn't display at all. I need to get OFC2 to generate different ids. How can I accomplish this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不乱于心 2024-10-03 14:35:41

事实证明,例如,您可以在控制器中紧随“analytics/pie1”之后指定一个 id。通过专门指定 ID,我们消除了算法生成相同数字并因此无法显示图像的任何可能性。

示例:@graph = ofc2( 440, 310, 'analytics/pie1', '/', 'my_unique_div' )

It turns out that you can specify an id in your controller right after 'analytics/pie1', for example. By specifying the ID specifically, we eliminate any chance of an algorithm generating the same number and therefore failing to show the images.

Example: @graph = ofc2( 440, 310, 'analytics/pie1', '/', 'my_unique_div' )

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文