ChartKick JavaScript追加有效,但克隆无效

时间:2018-09-28 15:55:26

标签: javascript ruby-on-rails chart.js haml chartkick

这应该很简单,但是我在此上浪费了很多时间。

我正在使用chartkick来获取红宝石。

我正在遍历一个对象数组以针对每个对象构建图表。以下haml代码被编写在循环内部。

%a.article-stats-btn{data:{no:{turbolinks:'false'}}}
  %span.glyphicon-stats.glyphicon.stats-icon 
  View Stats
  .chart
    = line_chart chartInfo

chartInfo包含有关循环的每次迭代的数据。这可以正常工作,并显示图表。现在,当有人单击<a>标记时,应将图表复制并显示在模式框中。

  $(".article-stats-btn").click(function(){
    $(this).find('.chart').appendTo('.chart-body'); // this works
    $(this).find('.chart').clone().appendTo('.chart-body'); // this doesn't
  });

如果我在没有appendTo的情况下使用clone(),它将起作用,但这会导致图表从其原始位置中删除。我想保留图表的位置,然后将其复制到模式.chart-body标记中。

模态看起来像这样。

.modal.fade.modal-fade#mymodal
  .modal-dialog
    .modal-content
      .modal-header
        %b Journal Stats
        %button.close{type:'button', data:{dismiss:'modal'}}
          %span{aria:{hidden:'true'}}
            %i.fa.fa-close
          %span.sr-only Close
        %h4.modal-title
      .modal-body.chart-body
      .modal-footer
        %button.btn.btn-default{type:'button', data:{dismiss:'modal'}} Close

更新

没有克隆:

enter image description here

使用克隆:

enter image description here

0 个答案:

没有答案