Javascript 错误:对象不是向回调函数返回数组的函数
我正在从UI逐行读取表值。我通过单击每行并读取每个值来读取表Javascript 错误:对象不是向回调函数返回数组的函数,javascript,arrays,node.js,webdriver-io,Javascript,Arrays,Node.js,Webdriver Io,我正在从UI逐行读取表值。我通过单击每行并读取每个值来读取表 exports.getTableData = function(callback){ var uiArray =[]; var count; aLib.loadCheck(client); //Clicks the first record of the table aLib.controlClick(client, obj.table.firstRecord); aLi
exports.getTableData = function(callback){
var uiArray =[];
var count;
aLib.loadCheck(client);
//Clicks the first record of the table
aLib.controlClick(client, obj.table.firstRecord);
aLib.loadCheck(client);
// Gets the text of the total number of records on the top left of the table and uses it to drive the loop
client.getText(obj.topContent.recordCount, function (err, rowNum){
console.log(rowNum);
count = rowNum.match(/\d/g).join("");
console.log('No. of records on UI:', count);
// Recursive function which clicks, reads the text in the selected row, and then clicks the next immediate row.
// This way, the dynamic nature of the records appearing in the DOM, as one scrolls down is handled.
function forLoop(i){
client.getText(obj.table.selectedRow, function (err, text){
var str = text.toString();//coverted UI text to string
str = str.replace(/\n/g,",");//converted next line(\n/g) to comma
str = str.replace(/\s/g, '');//removed blank space(\s/g)
var text = str.split(',');//converted string to array again
removed = text.splice(1,1);// removed updated by from UI
removed = text.splice(6,1);// removed inserted on from UI
removed = text.splice(7,2);// removed created by id from UI
// console.log(text.length);
uiArray.push.apply(uiArray, text);
// console.log('UI array ki length',uiArray.length);
console.log('i ki value :',i)
if(i==count){
console.log('inside if..............');
console.log(uiArray);
return callback(uiArray);
}
client.click(obj.table.nextRow);
forLoop(i+1);
});
}
forLoop(1);
});
};
我的脚本调用这个函数getTableData。
试试{
aLib.getTableData(client, function (uiTable){
console.log('suman00');
console.log(uiTable);
});
client.pause(12000);
} catch (e) {
expect(false).toBe(true);
throw new Error('testcase case failed because of exception : ' + e);
}
client.call(done);
},250000);
我在返回回调(uiArray);
您正在使用两个参数调用
getTableData()
,第二个参数是回调:
aLib.getTableData(client, function (uiTable){
但是,可以使用一个参数定义函数:
exports.getTableData = function(callback){
因此,您试图将对象客户机
作为函数调用,但该函数无法工作
您定义的参数应与传递的参数匹配,例如:
exports.getTableData = function(client, callback){
问题似乎不在于uiArray,而在于回调 该错误表示在代码中的某个地方,您正在使用对象而不是函数调用
exports.getTableData
然后,当您尝试
返回回调(uiArray);
时,您会得到错误。看起来您的函数只接受一个参数,而您正在将回调作为第二个参数传入。yuuuuu…!!非常感谢您…它成功了。
exports.getTableData = function(client, callback){