【问题标题】:Why is Handlebarsjs template missing jquery mobile CSS styles?为什么 Handlebarsjs 模板缺少 jquery 移动 CSS 样式?
【发布时间】:2012-07-29 04:47:10
【问题描述】:

我在 jquery 移动页面中使用 Handlebarsjs,当我从服务器获取回传的数据时,它被插入到模板中......但是没有任何 jquery 移动 CSS 样式应用于模板内的代码.

我的模板如下所示:

            <script id="card_list_template" type="text/x-handlebars-template">
            {{#each this}}
            <li>
                <a href="#">
                    <img src="{{path}}" />
                    <h3>{{first_name}}&nbsp;{{last_name}}</h3>
                    <p>Card Owner:&nbsp;{{user_id}}</p>
                </a>
            </li>
            {{/each}}
        </script>

上面的代码块被插入到这个无序列表中:

&lt;ul id="search_results" data-role="listview" data-theme="a"&gt;

data-role="listview" 应该为列表项应用某种样式,但它不适用于通过模板生成的项目。

【问题讨论】:

标签: jquery jquery-mobile handlebars.js


【解决方案1】:

如果你在元素上调用.trigger('create'),它应该应用样式。

例子:

var template = Handlebars.compile(source);
var html = template(output);
$('#handlebarsData').html(html);
// Applies jQuery Mobile styles
$('#handlebarsData').trigger('create');

【讨论】:

    【解决方案2】:
    .trigger('create')
    

    没有帮助我处理无序列表。但是

    $('ul').listview('refresh');
    

    做了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-14
      • 2018-08-31
      • 2017-10-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多