gpt4 book ai didi

javascript - 错误 :Object is not a function for returning an array to my callback function

转载 作者:行者123 更新时间:2023-11-29 21:16:20 25 4
gpt4 key购买 nike

我正在从 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);
    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);

我在 return callback(uiArray); 处遇到问题

console.log(uiArray);  //this returns value successfully.however i am unable to return the array to my script.

最佳答案

您使用两个参数调用 getTableData(),第二个参数是回调:

aLib.getTableData(client, function (uiTable){

但是,您使用一个参数定义函数:

exports.getTableData = function(callback){

因此,您试图将对象 client 作为函数调用,但这是行不通的。


您定义的参数应与传递的参数匹配,例如:

exports.getTableData = function(client, callback){

关于javascript - 错误 :Object is not a function for returning an array to my callback function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39293747/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com