1

我想初始化simpleSchema中的一个字段。我想将userId设置为一个字符串字段。将meteor.userId插入到mongoDB中

这里是架构:

AdsSchema = new SimpleSchema({ 
    title: { 
    type: String, 
    label: "Title" 
    }, 
    insertedBy: { 
    type: String, 
    label: "Inserted By", 
    autoform:{ 
     type:"hidden" 
    }, 
    autoValue: function() { 
     if (this.userId) { 
     return this.userId; 
     } 
    } 
    } 
} 

而是通过自动窗体插入后,插入的文件是:

{ 
    "_id" : "Zm5TML5bwJhyN8B9F", 
    "title" : "test" 
} 

它意味着 “insertedBy” 字段 “空” 值!

我该如何解决这个问题?

回答

1

尝试用if(Meteor.userId()) return Meteor.userId()

在autoValue this有限属性,检查文件Autoform Docs

开办关于autoValue一个小书房,在cleaning Data存在的财产extendAutoValueContext一提,这有助于使用用户id 。

+0

我使用Meteor.userId()代替this.userId,并解决了问题。谢谢 – Roohollah