我在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}} {{last_name}}</h3>
<p>Card Owner: {{user_id}}</p>
</a>
</li>
{{/each}}
</script>
上面的代码块将插入到此无序列表中:
<ul id="search_results" data-role="listview" data-theme="a">
data-role =“ listview”应该对列表项应用某种样式,但不适用于通过模板生成的项。
最佳答案
如果在元素上调用.trigger('create')
,则应应用样式。
例:
var template = Handlebars.compile(source);
var html = template(output);
$('#handlebarsData').html(html);
// Applies jQuery Mobile styles
$('#handlebarsData').trigger('create');
关于jquery - 为什么Handlebarsjs模板缺少jquery移动CSS样式?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11706750/