【问题标题】:collection record is empty return in meteor . why?收集记录是流星中的空返回。为什么?
【发布时间】:2016-04-22 16:39:56
【问题描述】:

我正在尝试对具有 google 和默认帐户登录的流星 crud 操作示例做出反应。用户登录显示为自己的记录。

createContainer 函数将联系人返回为[ ],为什么?

首先我尝试使用谷歌帐户登录,它工作正常。之后,我添加了流星帐户 ui 和帐户密码。然后它给了我空联系人。所以这里必须缺少一些东西才能使用流星帐户 ui。

这是我所做的。

list.jsx

export default createContainer(() => {

    return {
        contacts: Contact.find({}).fetch(),
        user: Meteor.user(),
    };

}, ContactList);

我的架构:-

export const Contact = new Mongo.Collection('contact');


Meteor.methods({

'contacts.insert'(firstName,lastName,email,password){
     if (!Meteor.userId()) {
            throw new Meteor.Error('not-authorized');
        }

    ContactSchema = new SimpleSchema({
    "firstName": {
        type: String
    },

    "lastName": {
        type: String
    },
    "email": {
        type: String,
        regEx: SimpleSchema.RegEx.Email,
        label: "E-mail address"
    },
    "password": {
        type: String,
        min:6,
        label:'password at least 6 character'
    },
    "owner": {type: String},
    "createdAt": {type: Date}
 });

Contact.insert({
    firstName,
    lastName,
    email,
    password,
    createdAt: new Date(),
    owner: Meteor.userId()
});

Contact.attachSchema(ContactSchema);

 },

【问题讨论】:

    标签: mongodb meteor reactjs


    【解决方案1】:

    .fetch() 方法不是响应式的,所以传递给容器的是光标的当前状态。最可能的问题是初始化发生在从服务器获取数据之前,因此集合仍然是空的。

    只需删除 .fetch() 方法并将数据作为反应式光标传递:contacts: Contact.find({}),。当然,在容器中使用游标方法而不是数组方法。然后,一旦出现新数据,容器就会自行刷新。

    【讨论】:

    • 所以不需要任何代码。我得到了解决方案。我更新了包,所以工作正常。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-27
    • 2015-07-25
    • 1970-01-01
    • 1970-01-01
    • 2015-08-07
    • 2015-07-22
    相关资源
    最近更新 更多