Javascript Meteor中的简单模式错误
我使用meteor帐户和简单模式让用户在我的应用程序中注册和输入他们的个人资料信息。我为用户定义了一个模式,并为地址附加了一个模式。然而,当我去注册一个帐户时,我不断地得到错误“Address required”,尽管我填写了Address的所有必填字段。以下是我的模式:Javascript Meteor中的简单模式错误,javascript,meteor,schema,accounts,Javascript,Meteor,Schema,Accounts,我使用meteor帐户和简单模式让用户在我的应用程序中注册和输入他们的个人资料信息。我为用户定义了一个模式,并为地址附加了一个模式。然而,当我去注册一个帐户时,我不断地得到错误“Address required”,尽管我填写了Address的所有必填字段。以下是我的模式: Schemas.UserAddress = new SimpleSchema({ //UserAddress schema defined streetAddress: { type: String, max
Schemas.UserAddress = new SimpleSchema({ //UserAddress schema defined
streetAddress: {
type: String,
max: 100,
optional: false
},
city: {
type: String,
max: 50,
optional: false
},
state: {
type: String,
regEx: /^A[LKSZRAEP]|C[AOT]|D[EC]|F[LM]|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ADEHINOPST]|N[CDEHJMVY]|O[HKR]|P[ARW]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY]$/,
optional: false
},
zipCode: {
type: String,
regEx: /^[0-9]{5}$/,
optional: false
}
});
以下是创建注册表单的“我的帐户”配置:
Meteor.startup(function () {
AccountsEntry.config({
logo: '', // if set displays logo above sign-in options
termsUrl: '/terms-of-use', // if set adds link to terms 'you agree to ...' on sign-up page
homeRoute: '/', // mandatory - path to redirect to after sign-out
dashboardRoute: '/dashboard/', // mandatory - path to redirect to after successful sign-in
profileRoute: '/profile',
passwordSignupFields: 'EMAIL_ONLY',
showOtherLoginServices: true, // Set to false to hide oauth login buttons on the signin/signup pages. Useful if you are using something like accounts-meld or want to oauth for api access
extraSignUpFields: [
{
field: "companyName",
label: "Company Name",
placeholder: "Petrocon",
type: "text",
required: true
},
{
field: "firstName",
label: "First Name",
placeholder: "John",
type: "text",
required: true
},
{
field: "lastName",
label: "Last Name",
placeholder: "Nguyen",
type: "text",
required: true
},
{ field: "streetAddress",
label: "Street Address",
placeholder: "12345 Main Street",
type: "text",
required: true
},
{ field: "city",
label: "City",
placeholder: "Springfield",
type: "text",
required: true
},
{ field: "state",
label: "State",
placeholder: "Missouri",
type: "text",
required: true
},
{ field: "zipCode",
label: "Zip Code",
placeholder: "65801",
type: "text",
required: true
},
{
field: "phoneNum",
label: "Contact Number",
placeholder: "316-000-0000",
type: "text",
required: true
}
]
});
});
如您所见,我在AccountsEntry.config中定义了地址模式中的所有字段。。因此,我不知道为什么当我在表单中输入所有信息时,会出现错误“address required”。有人知道发生了什么事吗?提前谢谢你 看起来您正在使用accounts entry软件包。您可以在此文件中看到创建帐户的代码: 第29行如下所示:
profile: _.extend(profile, user.profile)
如果在调用extend方法后调试并查看profile的值,您将看到:
{
"companyName": "Petrocon",
"firstName": "John",
"lastName": "Nguyen",
"streetAddress": "12345 Main Street",
"city": "Springfield",
"state": "Missouri",
"zipCode": "65801",
"phoneNum": "316-000-0000"
}
您的架构没有名为“address”的属性。用户架构
可能有一些巧妙的方法来完成您想要的任务,但是最简单的方法就是去掉Schemas.UserAddress模式。将这些属性(streetAddress、city、state、zipCode)移动到Schemas.UserProfile模式中,它就会工作。谢谢标记。我需要使用这个方法,因为我的用户可以有多个地址。另外,在我的模式中有一个名为“address”的属性。用户模式-它就在profile属性的正下方。你没有理解我的观点。您的架构中有一个名为address的属性,但您没有填充它,因此在架构验证期间它会被拒绝。此外,如果需要多个地址,则需要将address属性设置为数组。
{
"companyName": "Petrocon",
"firstName": "John",
"lastName": "Nguyen",
"streetAddress": "12345 Main Street",
"city": "Springfield",
"state": "Missouri",
"zipCode": "65801",
"phoneNum": "316-000-0000"
}