【发布时间】:2014-05-01 04:11:26
【问题描述】:
我刚刚升级到 Meteor 0.8,并注意到我的列表视图刷新不再起作用,这意味着我看到了数据,但没有应用 jQuery-Mobile 样式。我正在使用 1.4.2,这与 0.7.2 的 Meteor 使用效果很好:
Template.requests.rendered = function(){
if ($('[data-role="listview"]')) {
$('[data-role="listview"]').listview().listview("refresh");
}
}
有其他人看到这种行为并知道解决方法吗?
这是我的模板的样子:
<template name="requests">
<div id="listview-content">
<ul data-role="listview" data-autodividers="false" data-filter="true" data-inset="true">
{{#each items}}
<li><a href="#listdetail" data-name="{{RequestedFor}}" data-transition="slide">{{RequestedFor}}<br><span
class="small">Requested new {{RequestedItem}} on {{formatDate dateSubmitted "short"}}</span></a>
</li>
{{/each}}
</ul>
</div>
</template>
问题似乎是模板渲染事件确实尚未渲染数据,因此它试图对尚不存在的内容进行列表视图刷新。现在,我做这个 hack,但我当然不想保留它:
Template.requests.rendered = function(){
Meteor.setTimeout(function() {
if ($('[data-role="listview"]')) {
$('[data-role="listview"]').listview().listview("refresh");
}
}, 300); //Must be >= 300ms to render the listview properly
};
【问题讨论】:
-
如果您要添加新的
ul,请仅使用.listview()。如果您要将li添加到现有的ul,请仅使用.listview("refresh")。 -
我都试过了,但这不起作用,因为列表视图还不可见。在列表视图可见之后,我需要一种方法来执行此操作,然后我希望它可以工作。问题是我似乎找不到使用流星的方法。
-
没有错误。只是不应用样式。
-
我也遇到过这个问题。调用渲染时似乎 DOM 尚未准备好。:(
-
尝试参考这个答案“推荐的模式是将 {{#each}} 的内容放在单独的模板中,然后点击该模板的渲染事件。” stackoverflow.com/questions/22790936/…
标签: jquery-mobile meteor