Meteor cursor.fetch().property returns "undefined"

Meteor cursor.fetch().property returns "undefined"

本文关键字:quot undefined returns property cursor fetch Meteor      更新时间:2023-09-26

我有一个简单的助手,可以将数组返回到模板中的 #each 块。这工作正常,并且显示标签。

但是,我不明白为什么我不能控制台.log用户标签的属性,例如userTags.BusinessContact。但是我可以控制台.log完整的对象,因此(控制台.log(用户标签))将起作用。

    Template.profileTags.helpers({
        tag:function(){
            var userTags = tikiUser.find({}).fetch()
            //this returns "undefined" 2 times
            Meteor.setTimeout(function(){console.log(userTags.BusinessContact)}, 500)
            return userTags
        }
    })

为什么?

感谢

您正在尝试获取数组的 BusinessContact 属性 - 尝试执行

 userTags[0].BusinessContact

PS:发布问题时尝试 meteorpad.com

试试这个。

if(userTags)
 {
   Console.log(userTags.BusinessContact)
    }

在 meteor 中,有些时候我们不会第一次得到值,所以,如果我们写一个 if 条件,那么它只会检查那里的值。

希望这对你有帮助。