我已经安装了陨石和路由器包
现在我有一个主页app.html
<body>
<div class="container">
<div class="page-header">
<a href="/">
<h1>Mi page</h1>
</a>
</div>
<div class="content">
{{renderPage}}
</div>
</div>
</body>
好的,现在所有页面都在 {{renderPage}} 中渲染。
现在用户转到/panel 并呈现用户面板,这是棘手的部分
此部分有一个 cpanel_nav_div 和一个 cpanel_body,我认为当用户保留在面板部分时,每次用户单击面板选项链接之一时 cpanel_nav_div 不会渲染,因此只有 cpanel_body 发生变化,这样效率更高。
最好的方法是什么??
它有一种方法可以执行其他路由器和过滤器路由,因此当路由匹配/panel/... 时,所有内容都会进入 cpanel_body 而不是进入 {{renderPage}} ???
设置 Session.get 和 Session.set 并根据 session 在 cpanel_body 内渲染内容(这样我们就错过了路由)
每次使用路由并渲染 cpanel_nav 和 cpanel_body ?
感谢您的帮助
最佳答案
您可以使用 preserve 告诉 Meteor 不要重新渲染模板的一部分。 :
You can "preserve" a DOM element during re-rendering, leaving the existing element in place in the document while replacing the surrounding HTML. This means that re-rendering a template need not disturb text fields, iframes, and other sensitive elements it contains. The elements to preserve must be present both as nodes in the old DOM and as tags in the new HTML. Meteor will patch the DOM around the preserved elements.
For example, to preserve all elements with ids in template 'foo', use:
Template.foo.preserve({ 'input[id]': function (node) { return node.id; } });
因此,您可能希望使用preserve方法告诉Meteor不要重新渲染您的cpanel_nav_div元素。
关于javascript - Meteorjs有效显示管理面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13930569/