Meteor.JS - accounts-password:TypeError:Accounts.createUser不是函数

时间:2016-01-07 08:12:48

标签: javascript meteor meteor-accounts

我正在创建一个应用并收到以下错误:

TypeError:Accounts.createUser不是函数

这是我的代码:

    Template.register.events({
    'submit form': function(event){
    event.preventDefault();
    var email = $('[name=email]').val();
    var password = $('[name=password]').val();
        var fname = $('[name=fname]').val();
        var lname = $('[name=lname]').val();

    Accounts.createUser({
        email: email,
        password: password,
            profile: {
            fname: fname,
            lname: lname,
            IsActive: 0
            }

    });
    Router.go('home');
    }
});

我使用的是:accounts-password package

我也在使用MONGO_URL(MONGO_URL = mongodb:// localhost:27017 / MYDB)

我试过了:meteor reset

还通过以下方式重新创建了应用程序:meteor create myapp

我可以通过已经创建的用户登录,以前它没有给出任何问题,我创建了一个用户,但现在它正在解决这个问题,我该怎么办?

2 个答案:

答案 0 :(得分:1)

以下是我做错了:

我使用的是一个名为Accounts的集合,见下文:

旧代码

Accounts = new Meteor.Collection('accounts');

订阅:

Meteor.publish('Accounts', function(){
return Accounts.find();
});

并使用助手:

Template.account_screen_account_view.helpers({

FetchAccountViewData: function () {
var editid = Router.current().params._id;
return CustomerAccounts.findOne({_id:editid});
}

});

与以下代码冲突:

  Accounts.createUser({
    email: email,
    password: password,
        profile: {
        fname: fname,
        lname: lname,
        IsActive: 0
        }

});

新代码(已更改)

CustomerAccounts = new Meteor.Collection('customeraccounts');

Meteor.publish('CustomerAccounts', function(){
return CustomerAccounts.find();
});


Template.account_screen_account_view.helpers({

FetchAccountViewData: function () {
var editid = Router.current().params._id;
return CustomerAccounts.findOne({_id:editid});
}

});

现在问题已解决。有时我们会忘记查看这些内容,我很乐意分享我的经验,就像您使用Meteor帐户一样,然后您需要更改自己的集合和功能的名称,因为它们可能会发生冲突并产生这些类型的问题。

答案 1 :(得分:0)

请验证您的字段名称是否相同。 如果这些是相同的尝试:

funname:function(event,target){
    email=target.find(".your field class name or # field id").value;

}

相关问题