0

私は流星アプリにこのコードを持っています:

// client side
Template.lead.events({
    'submit .insertExternalAccountForm': function (event) {
        event.preventDefault();
        Session.set('mcsStatus', 'Creating external account ...');

        var target = {
            code: event.target.code.value,
            leadId: event.target.leadId.value,
            name: event.target.name.value,
            username: event.target.username.value,
            password: event.target.password.value,
            searchSourceId: event.target.searchSourceId.value,
            clientId: event.target.clientId.value,
            clientUserId: event.target.clientUserId.value
        };

        var noFormError = true;
        if (target.username.length === 0) {
            Session.set("username_error", "Field must not be empty");
            noFormError = false;
        } else {
            Session.set("username_error", null);
        }

        if (target.password.length === 0) {
            Session.set("password_error", "password must not be empty");
            noFormError = false;
        } else {
            Session.set("password_error", null);
        }

        if (!noFormError) {
            return noFormError;
        }

        Meteor.call('createExternalAccount', target, function (err, res) {
            if (err) {
                console.error(err);
            }
            console.log('in meteor call');
            Router.go('/' + res.domain + '/' + res.externalId);
        });
    }
});

//server side

var createExternalAccountSync = function (query, external) {
    return models.SearchSources.findOne(query).exec()
    .then(function (searchsource) {
        external.domain = searchsource.source;
        var emr = searchsource.source.split('-');
        return models.Organization.findOne({externalId: emr[2]}).exec();
    }).then(function (org) {
        console.log('after org');
        external.organizationId = org._id;
        return models.AppUser.findOne({clientId: external.clientId, externalId: external.clientUserId }).exec();
    }).then(function (user) {
        console.log('after app user');
        external.userId = user._id;
        external.userIds = [user._id];
        return new Promise(function (resolve,reject) {
            console.log('saveOrUpdate');
            models.ExternalAccount.saveOrUpdate(external, function (err, newE) {
                if (err) {
                    console.error(err)
                    reject(err);
                }
                resolve(newE)
            });
        });
    })
    .catch(function (e) {
        console.error(e);
        throw new Meteor.Error(e);
    });
};


Meteor.methods({'createExternalAccount': function (data) {
        var query = {};
        var newExternalAccount = new models.ExternalAccount();

        newExternalAccount.username = data.username;
        newExternalAccount.password = data.password;
        newExternalAccount.externalId = data.username;
        newExternalAccount.name = data.name;
        newExternalAccount.clientId = data.clientId;
        newExternalAccount.clientUserId = data.clientUserId;
        newExternalAccount._metadata = { leadId: data.leadId };
        if (data.code === 'f') {
            query.searchSourceId = '5744f0925db77e3e42136924';
        } else {
            query.searchSourceId = data.searchSourceId;
        }

        newExternalAccount.searchSourceId = query.searchSourceId;
        console.log('creating external account')
        createExternalAccountSync(query, newExternalAccount)
        .then(function (external) {
            console.log('should return to meteor call');
            return external;
        })
        .catch(function (e) {
            console.error(e);
            throw new Meteor.Error(e);
        });
    }
});

私が抱えている問題は、サーバー側のコードが適切に呼び出されている間、クライアント側の meteor.call をトリガーしていないことです。console.log 出力などはありません。Meteor.wrapAsync メソッドは適切に使用されていると思いますが、クライアント側にはまだ何も表示されておらず、実際にはフォーム送信後にユーザーが行きたい場所にリダイレクトされていません。

アップデート

コードは最新の形式に更新されていますが、クライアントで奇妙なエラーが発生しています。実際には、テンプレートの meteor.call メソッドがエラーも結果も返さないためです。

Exception in delivering result of invoking 'createExternalAccount': http://localhost:3000/app/app.js?hash=c61e16cef6474ef12f0289b3f8662d8a83a184ab:540:40
http://localhost:3000/packages/meteor.js?hash=ae8b8affa9680bf9720bd8f7fa112f13a62f71c3:1105:27
_maybeInvokeCallback@http://localhost:3000/packages/ddp-client.js?hash=27502404fad7fc072e57e8b0b6719f40d92709c7:3557:21
receiveResult@http://localhost:3000/packages/ddp-client.js?hash=27502404fad7fc072e57e8b0b6719f40d92709c7:3577:30
_livedata_result@http://localhost:3000/packages/ddp-client.js?hash=27502404fad7fc072e57e8b0b6719f40d92709c7:4742:22
onMessage@http://localhost:3000/packages/ddp-client.js?hash=27502404fad7fc072e57e8b0b6719f40d92709c7:3385:28
http://localhost:3000/packages/ddp-client.js?hash=27502404fad7fc072e57e8b0b6719f40d92709c7:2736:19
forEach@[native code]
forEach@http://localhost:3000/packages/underscore.js?hash=27b3d669b418de8577518760446467e6ff429b1e:149:18
onmessage@http://localhost:3000/packages/ddp-client.js?hash=27502404fad7fc072e57e8b0b6719f40d92709c7:2735:15
dispatchEvent@http://localhost:3000/packages/ddp-client.js?hash=27502404fad7fc072e57e8b0b6719f40d92709c7:175:27
_dispatchMessage@http://localhost:3000/packages/ddp-client.js?hash=27502404fad7fc072e57e8b0b6719f40d92709c7:1160:23
_didMessage@http://localhost:3000/packages/ddp-client.js?hash=27502404fad7fc072e57e8b0b6719f40d92709c7:1218:34
onmessage@http://localhost:3000/packages/ddp-client.js?hash=27502404fad7fc072e57e8b0b6719f40d92709c7:1365:28
4

1 に答える 1

0

あなたが提供したコードでは、別のメソッドを呼び出している可能性があります。

「createAccount」を定義しましたが、クライアント側で「createExternalAccount」を呼び出しています

于 2016-07-09T20:49:30.150 に答える