【问题标题】:Rateit plugin not working when used in Mustache.js template在 Mustache.js 模板中使用时,Rateit 插件不起作用
【发布时间】:2014-08-10 21:42:50
【问题描述】:

我在 Mustache.js 模板中使用了 RateIt Pugin,但它没有显示任何内容。

当我在 HTML 中直接使用 RateIt 时,它工作正常

下面是我的小胡子模板

<script id="category_list" type="text/template">
  <li> Rate {{movie_name}}:
      <div  class="rateit">
      </div>
  </li> 
</script>

下面是我获取模板并将其添加到主页的 JS 代码

 var data={
            movie_name:'some movie'
        };
$.get('js/temp.html', function(template, textStatus, jqXhr) {
    var menu_list=Mustache.render($(template).filter('#category_list').html(), data);
    $('#movie_details_list').empty().append(menu_list);
    $.mobile.changePage( '#movie_details_page', { transition: "slide", changeHash: false });
});

这是我的 HTML

<div data-role="page" id="home">
    <div data-role="content">
      <ul data-role="listview" id="movie_details_list" >
      </ul>
    </div>
  </div>

【问题讨论】:

    标签: javascript jquery jquery-mobile jquery-plugins mustache


    【解决方案1】:

    您必须在加载模板后触发rateit()。没看懂你result/template的逻辑,做了一些调整:

    var template = $('#category_list').html();
    Mustache.parse(template);
    var data={
       movie_name:'Stack in the Galaxy'
    };
    $.get('temp.html', function( result, textStatus, jqXhr ) {
        var rendered = Mustache.render( template, data );
        $('#target').html( result );
        $('#movie_details_list').append( rendered );
        $('div.rateit, span.rateit').rateit(); // <-- start up RateIt
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-21
      • 2013-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-25
      相关资源
      最近更新 更多