集合查找方法不适用于Angular 2递归函数

时间:2017-03-27 20:15:15

标签: mongodb angular meteor recursion

我正在使用Meteor开发Angular2。

当我使用递归函数创建一个小组件时,它有一些奇怪的错误。

这是我的代码部分。

不递归 - 返回结果

ngOnInit() {
        //this.current_canvas return the right results
        this.current_canvas = this.get_canvase(1);
}
get_canvase(which_canvas): Canvas[] {
    if (!isNaN(which_canvas)) {
        this.current_canvas_id = which_canvas;
        return CanvasContents.find().map((messages: Canvas[]) => { return messages; })[0].content;
        return '';
    } else if(which_canvas == 'most-recent') {
        this.get_canvase(1);
    }
}

递归 - 不返回结果

ngOnInit() {
        //this.current_canvas Goes to NUll
        this.current_canvas = this.get_canvase('most-recent');
}
get_canvase(which_canvas): Canvas[] {
    if (!isNaN(which_canvas)) {
        this.current_canvas_id = which_canvas;
        console.log('this.current_canvas_id : ' + this.current_canvas_id);
        return CanvasContents.find().map((messages: Canvas[]) => { return messages; })[0].content;
        return '';
    } else if(which_canvas == 'most-recent') {
        this.get_canvase(1);
    }
}

我使用了错误的语法吗?或者是否在错误的Angular2状态下获得正确的结果?

0 个答案:

没有答案