我正在努力解决如果用户没有登录而将用户重定向到登录页面的常见需求(Windows 7上的Meteor v0.8.0).
stackoverflow上有几个类似的问题,但似乎没有答案对我有用.
不会工作#1:render()
从文档:
onBeforeAction: function () {
if (!Meteor.user()) {
// render the login template but keep the url in the browser the same
this.render('login');
// stop the rest of the before hooks and the action function
this.stop();
}
},
Run Code Online (Sandbox Code Playgroud)
这里有两个问题:
1-文档已过时.没有this.stop()功能了.如前所述这里的代码应该是:
onBeforeAction: function (pause) {
if (!Meteor.user()) {
// render the login template but keep the url in the browser the same
this.render('login');
// stop the rest of the before …Run Code Online (Sandbox Code Playgroud) 请考虑以下代码:
Template.fullDoc.rendered = function() {
// Get triggered whenever the selected document id changes
this.autorun(function() {
var docId = isolateValue(function() {
return Template.currentData().selectedDoc._id;
});
...
});
}
Run Code Online (Sandbox Code Playgroud)
此代码不起作用.在里面isolateValue(),Template.currentData()有时会触发异常:( Exception from Tracker recompute function: Error: There is no current view这对应于Template.instance()返回的事实null).
那么如何在模板数据上下文的子部分设置反应依赖?