我想在回调函数中使用多个值
myfunction(i,function(err,result){ console.log(JSON.parse(JSON.strigify(result))); ****//i need value here..**** });
function myfunction(i,callback) {
/* my some stuff */
var callBackString= new Array();
callBackString['value1']=value1;
callBackString['value2']= value2;
callBackString['value3']= value3;
callback(null,callBackString);
};
我将callBackString作为一个数组重新启动..,
有谁可以告诉我该怎么做
由于
答案 0 :(得分:6)
您应该使用对象:
function myfunction(i, callback) {
var callBackString = {};
callBackString.value1 = value1;
callBackString.value2 = value2;
callBackString.value3 = value3;
callback(null, callBackString);
}
接收端:
myfunction(i, function(err, result) {
var value1 = result.value1;
var value2 = result.value2;
var value3 = result.value3;
console.log(JSON.parse(JSON.strigify(result)));
});
答案 1 :(得分:0)
以下内容应该有效:
function myfunction(i, callback) {
// ...
// Returns an Array
return callback(null, [value1, value2, value3])
}
function myfunction2(i, callback) {
// ...
// Returns an Object
return callback(null, {value1: value1, value2: value2, value3: value3})
}
答案 2 :(得分:-1)
试试这个
希望它有效
myfunction(i,function(err,value1,value2,value3){
console.log(JSON.parse(JSON.strigify(result)));
****//i need value here..****
});
function myfunction(i,callback) {
/* my some stuff */
var callBackString= new Array();
callBackString['value1']=value1;
callBackString['value2']= value2;
callBackString['value3']= value3;
callback(null,value1,value2,value3);
};