无法从量角器回调中访问数组 [英] Can't access array from within protractor callback
本文介绍了无法从量角器回调中访问数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是量角器和 javascript 的新手.我遇到了一个我无法弄清楚的范围界定问题.在下面的代码段中,第一个数组访问语句有效,但第二个无效.什么给?
I'm new to both protractor and javascript. I ran into a scoping issue which I can't figure out. In the code segment below, the first array access statement works but the second doesn't. What gives?
for(var i=0;i<=1;i++){
console.log(msgs[i]);
element.all(by.className("form-group")).get(i).element(by.className("alert alert-danger")).getText().then(function(txt){
console.log(msgs[i]);
});
}
推荐答案
你只需要改变
... .getText().then(function(txt){ ... });
到
... .getText().then((txt) => { ... });
它被称为粗箭头函数并且它没有自己的this
,因此您可以访问您的数组.
It's called fat arrow function and it does not have it's own this
so you can access your array.
这篇关于无法从量角器回调中访问数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文