Javascript 将VAR值置于承诺函数之外
我必须获得Javascript 将VAR值置于承诺函数之外,javascript,jasmine,protractor,Javascript,Jasmine,Protractor,我必须获得count的值才能执行for循环,我如何获得它?我在下面提供了示例代码: var listCount = usersPage.trOfRowInListPage.count(); listCount.then(function (realListCountValue) { console.log(realListCountValue); }); expect(listCount).toEqual(6);
count
的值才能执行for循环
,我如何获得它?我在下面提供了示例代码:
var listCount = usersPage.trOfRowInListPage.count();
listCount.then(function (realListCountValue) {
console.log(realListCountValue);
});
expect(listCount).toEqual(6);
for(var i=1; i<listCount; i++)
{
console.log(i);
}
var listCount=usersPage.trOfRowInListPage.count();
然后(函数(reallListCountValue){
console.log(realListCountValue);
});
期望(列表计数)。toEqual(6);
for(var i=1;i假设listCount是一个承诺,这应该会对您有所帮助。您的for循环将i
与一个承诺进行比较,而不是一个数字。我认为您想要做的是将其与承诺的结果进行比较,如下所示:
var realValue, listCount = usersPage.trOfRowInListPage.count();
listCount.then(function (realListCountValue) {
realValue = realListCountValue;
});
for(var i=1; i<realValue; i++) {
console.log(i);
}
var realValue,listCount=usersPage.trOfRowInListPage.count();
然后(函数(reallListCountValue){
realValue=realListCountValue;
});
for(var i=1;i假设listCount是一个承诺,这应该会对您有所帮助。您的for循环将i
与一个承诺进行比较,而不是一个数字。我认为您想要做的是将其与承诺的结果进行比较,如下所示:
var realValue, listCount = usersPage.trOfRowInListPage.count();
listCount.then(function (realListCountValue) {
realValue = realListCountValue;
});
for(var i=1; i<realValue; i++) {
console.log(i);
}
var realValue,listCount=usersPage.trOfRowInListPage.count();
然后(函数(reallListCountValue){
realValue=realListCountValue;
});
对于(var i=1;i您需要将循环放入then()
:
var listCount=usersPage.trOfRowInListPage.count();
然后(函数(reallListCountValue){
对于(var i=1;i您需要将循环放入then()
:
var listCount=usersPage.trOfRowInListPage.count();
然后(函数(reallListCountValue){
对于(var i=1;idoeslistCount
返回承诺?是否listCount
返回承诺?不,我没有得到所需的输出,我认为您理解正确。.“realvalue”或“listCount”在“expect”之外工作,而不是“for”循环。我认为我们没有得到承诺函数之外的整数值,还有其他方法吗?realListValue
返回什么?它不像listCount
返回承诺“listCount”返回长文本数据,而是“realListCountValue”以整数形式返回精确计数..不,我没有得到所需的输出,我认为您理解得对..“realvalue”或“listCount”在外部用于“expect”,但不用于“for”循环。我认为我们没有得到承诺函数之外的整数值,还有其他方法吗?realListValue
返回什么?它不像listCount
返回承诺“listCount”返回长文本数据,而是“realListCountValue”以整数形式返回精确计数。抱歉。没有办法取外部?@DeepakSabastein如果需要实际计数值,则必须将其放入then()
中。抱歉。没有办法取外部?@DeepakSabastein如果需要实际计数值,则必须将其放入then()
中。