Javascript 流星服务器中的Braintree Transaction.search

Javascript 流星服务器中的Braintree Transaction.search,javascript,asynchronous,meteor,wait,braintree,Javascript,Asynchronous,Meteor,Wait,Braintree,如何等待Braintree Transaction.search()函数返回所有数据。 现在它不等待,只返回未定义的返回值。 这是密码 我尝试使用Meteor.asynwrap,但也不起作用。 ` 找到了一种让它工作的方法: 1.添加了一个回调函数 函数getTrxns(cid,回调) 2.调用流中的回调。在('end;)上,下面是代码 function getTrxns(cid,callback ) { var trxns = []; var i

如何等待Braintree Transaction.search()函数返回所有数据。 现在它不等待,只返回未定义的返回值。 这是密码 我尝试使用Meteor.asynwrap,但也不起作用。 `


找到了一种让它工作的方法: 1.添加了一个回调函数
函数getTrxns(cid,回调
2.调用流中的回调。在('end;)上,下面是代码

         function getTrxns(cid,callback ) {

      var trxns = [];
      var i = 0
      var stream = gateway.transaction.search(function (search) {
                            r =     search.customerId().is(cid)});

      stream.on("data", function(data){
            i = i+1
            trxns.push({
               'id':data.id,
            });
     });
    stream.on("end", function(){
        // print the output in console
        console.log('End Stream cnt: '+i);
        callback('', trxns);
    });

    stream.resume();
    }



3. Changed the Meteor Method :

 findCustTrxns: function(btId) {


        if (!btId) { return []; };
        console.log('findCustTrxns cusBtId: '+btId);

 var trxns = [];
  var i = 0;

        var fn = Meteor.wrapAsync(getTrxns);  //made it a synchronous call
        try {
           var res = fn(btId);
           if (res) {
                console.log('Got data from getTrxns ');
                return res;
           }
        } catch( err) {
                console.log('Error calling hetTrxns '+err);
        }
 }, //findCustTrxns

现在我可以得到交易记录了。希望它有助于找到一种方法使其工作: 1.添加了一个回调函数
函数getTrxns(cid,回调
2.调用流中的回调。在('end;)上,下面是代码

         function getTrxns(cid,callback ) {

      var trxns = [];
      var i = 0
      var stream = gateway.transaction.search(function (search) {
                            r =     search.customerId().is(cid)});

      stream.on("data", function(data){
            i = i+1
            trxns.push({
               'id':data.id,
            });
     });
    stream.on("end", function(){
        // print the output in console
        console.log('End Stream cnt: '+i);
        callback('', trxns);
    });

    stream.resume();
    }



3. Changed the Meteor Method :

 findCustTrxns: function(btId) {


        if (!btId) { return []; };
        console.log('findCustTrxns cusBtId: '+btId);

 var trxns = [];
  var i = 0;

        var fn = Meteor.wrapAsync(getTrxns);  //made it a synchronous call
        try {
           var res = fn(btId);
           if (res) {
                console.log('Got data from getTrxns ');
                return res;
           }
        } catch( err) {
                console.log('Error calling hetTrxns '+err);
        }
 }, //findCustTrxns

现在我可以得到交易记录了。希望对您有所帮助

您使用的是哪种版本的Meteor?您使用的是哪种版本的Meteor?