【发布时间】:2015-07-14 18:55:33
【问题描述】:
我在 Meteor 中有一条路径
path: '/my-url/:groupId?',
我添加了问号以表明有时groupId 未被使用。在data 中,我检查组ID 是否设置为this.params.hasOwnProperty('groupId'),但我发现有时路由器认为groupId 已设置,即使它不是(不知道为什么)但值为undefined。
因此,我尝试了
console.log(this.params.hasOwnProperty('groupId'));
console.log('groupId' in this.params);
console.log(this.params.groupId);
他们评估为
> true
> true
> undefined
所以我猜hasOwnProperty 不是检查是否设置了groupId 的最佳方法,因为它不检查未定义的值。
有什么更好的方法来检查这个?即使我的网址是 /my-url,为什么 hasOwnProperty 评估为 true?
【问题讨论】:
-
你找到其他解决方案了吗
标签: javascript regex node.js meteor iron-router