私は約束を築きましたが、私はちょっと立ち往生しています。Meteorの約束を使って3つの通話を作成する方法
私はgetAllDataSource
をする必要がある - >createDashboard
- > `sendDashboard``
ので、コードは次のとおりです。
var call = Promise.promisify(Meteor.call, Meteor);
var calls = call(getAllDataSource()).
then(call.bind(Meteor, createDashboard())).
then(call.bind(Meteor, sendDashboard()));
calls.then(function(resThree){
console.log("Got Response!", resThree);
}).catch(function(err){
console.log("Got Error", err);
});
しかし、私は最初のVAR call
私は、私は必要だと思うと失われたビットですそれを変更するが、何と一緒に?そして、それがいつgetAllDataSource
が完了したかを知る方法は?
var allDataSources;
getAllDataSources = Meteor.bindEnvironment(function(){
HTTP.call("GET", 'http://localhost:3000/api/datasources', {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer eyJrIjoic2RRbU9oM2Rkbmc0bHZUSjVlTjBPckRVNlplSW1DYzEiLCJuIjoibG9jYWxob3N0X2FkbWluX2tleSIsImlkIjoxfQ==',
},
},
function(error, result) {
if (!error) {
allDataSources = result.data;
} else {
console.error(error);
}
});
});
var sendme;
createDashboard = Meteor.bindEnvironment(function(){
for (var i = 0; i < 5; i++) {
console.log("I have " + i + " apples in " + allDataSources);
sendme = "hihihih";
}
});
sendDashboard = Meteor.bindEnvironment(function(){
for (var i = 0; i < 7; i++) {
console.log("I have " + i + " cats with " + sendme);
}
});
結果が作成されると自動的に方法2に進みますか? [EDIT2] した後、私はこのエラーを得た@ymzの答えを続い
Got Error { [Error: Method 'undefined' not found [404]]
I20170209-10:39:30.990(1)? error: 404,
I20170209-10:39:30.991(1)? reason: 'Method \'undefined\' not found',
I20170209-10:39:30.991(1)? details: undefined,
I20170209-10:39:30.991(1)? message: 'Method \'undefined\' not found [404]',
I20170209-10:39:30.991(1)? errorType: 'Meteor.Error' }
:
は助け[EDIT]これは実際にコンソール上で私のことを与えていただき、ありがとうございます
Got Error { [Error: Method '[object Object],[object Object],[object Object],[object Object]' not found [404]]
I20170209-11:23:48.154(1)? error: 404,
I20170209-11:23:48.154(1)? reason: 'Method \'[object Object],[object Object],[object Object],[object Object]\' not found',
I20170209-11:23:48.154(1)? details: undefined,
I20170209-11:23:48.154(1)? message: 'Method \'[object Object],[object Object],[object Object],[object Object]\' not found [404]',
I20170209-11:23:48.154(1)? errorType: 'Meteor.Error' }
getAllDataSource()
はdata
の中に配列を入れているので、var calls = call(data).then .... // proceed from here
から来ると思います。私はもう少し助けを必要としてください
あなたは** VARの約束を使用していることを確認しています= require( 'bluebird'); **? – ymz
@ymz okこれは実際にエラーを解決しました!しかし、コードは正しいですか?私は、それぞれの呼び出しで 'メテオ 'は何ですか? – Jerome