小编ste*_*643的帖子

使用铁路由器重定向未登录的用户...再次

我正在努力解决如果用户没有登录而将用户重定向到登录页面的常见需求(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)

meteor iron-router

20
推荐指数
2
解决办法
1万
查看次数

在Meteor中,如何设置模板数据上下文的子部分的反应依赖?

请考虑以下代码:

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).

那么如何在模板数据上下文的子部分设置反应依赖?

meteor

4
推荐指数
1
解决办法
554
查看次数

标签 统计

meteor ×2

iron-router ×1