无法 return 包含来自 ag-grid table 的列值的数组返回到函数
Not able to return an array containing column values from an ag-grid table back to the function
我编写了一个函数,它读取 ag-grid 中的给定列并将其存储在数组中。
getSortedText(columnName: string){
var testArrayAsc = [];
element.all(by.css('div.ag-body-container > [role="row"]')).then(function(count) {
console.log("Row Count= ", Object.keys(count).length);
for (let rowNo = 0; rowNo < Object.keys(count).length; rowNo++) {
element.all(by.css(String.Format("div.ag-body-container div[ row-index='{0}'] > [col-id='{1}']", rowNo, columnName))).map(function (Element) {
Element.getText().then(function (result) {
console.log("Result Asc :: " + result);
testArrayAsc.push(result);
});
})
}
}).then(function () {
console.log("TestArrayAsc::",testArrayAsc);
return testArrayAsc;
})
}
我通过我的测试调用这个函数:
console.log('Array::', homepage.getSortedText('Betreff'));
但我得到 "Array:: undefined" 作为输出。
如果我像这样修改我的代码:
homepage.getSortedText('Betreff').then(function (a) {
})
然后我在 IDE 中收到此错误消息:"Property 'then' doesnot exist on type 'void'"。
请帮忙。提前致谢。
getSortedText
没有 return 任何东西,因此它是 void 类型并且没有 then
方法。
缺少很多信息,但起点是 return 您正在创建的 Promise。
return element.all(
我编写了一个函数,它读取 ag-grid 中的给定列并将其存储在数组中。
getSortedText(columnName: string){
var testArrayAsc = [];
element.all(by.css('div.ag-body-container > [role="row"]')).then(function(count) {
console.log("Row Count= ", Object.keys(count).length);
for (let rowNo = 0; rowNo < Object.keys(count).length; rowNo++) {
element.all(by.css(String.Format("div.ag-body-container div[ row-index='{0}'] > [col-id='{1}']", rowNo, columnName))).map(function (Element) {
Element.getText().then(function (result) {
console.log("Result Asc :: " + result);
testArrayAsc.push(result);
});
})
}
}).then(function () {
console.log("TestArrayAsc::",testArrayAsc);
return testArrayAsc;
})
}
我通过我的测试调用这个函数:
console.log('Array::', homepage.getSortedText('Betreff'));
但我得到 "Array:: undefined" 作为输出。
如果我像这样修改我的代码:
homepage.getSortedText('Betreff').then(function (a) {
})
然后我在 IDE 中收到此错误消息:"Property 'then' doesnot exist on type 'void'"。
请帮忙。提前致谢。
getSortedText
没有 return 任何东西,因此它是 void 类型并且没有 then
方法。
缺少很多信息,但起点是 return 您正在创建的 Promise。
return element.all(