我正在创建一个页面对象,需要有一个函数来检查是否禁用了一组元素。
我尝试了以下但是它不起作用。
areAllElementsDisabled: function (allElements) {
return allElements.filter(function (elem) {
return elem.isEnabled().then(function (isEnabled) {
return isEnabled;
});
}).length===0;
}
有人可以提出解决问题的方法吗?谢谢!
答案 0 :(得分:0)
如果有人遇到类似的问题,我找到了一种适合我的方式:
areAllElementsDisabled: function (allElements) {
var allElemetsPromises = allElements.map(function(elem){
return elem.isEnabled();
});
return Promise.all(allElemetsPromises).then(function(values){
return values.every(function(value){
return !value;
})
});
}
答案 1 :(得分:0)
您可以在过滤后的元素上调用Empty:
Empty: end
Added F:
Node: 'F' (ptr = 0x7fc63fc02750, left = 0x0, right = 0x0)
Added F: end
Added B:
Node: 'F' (ptr = 0x7fc63fc02750, left = 0x7fc63fc02770, right = 0x0)
Node: 'B' (ptr = 0x7fc63fc02770, left = 0x0, right = 0x0)
Added B: end
Added I:
Node: 'F' (ptr = 0x7fc63fc02750, left = 0x7fc63fc02770, right = 0x7fc63fc027f0)
Node: 'B' (ptr = 0x7fc63fc02770, left = 0x7fc63fc02810, right = 0x7fc63fc02790)
Node: 'A' (ptr = 0x7fc63fc02810, left = 0x0, right = 0x0)
Node: 'C' (ptr = 0x7fc63fc02790, left = 0x0, right = 0x7fc63fc027b0)
Node: 'D' (ptr = 0x7fc63fc027b0, left = 0x0, right = 0x7fc63fc027d0)
Node: 'E' (ptr = 0x7fc63fc027d0, left = 0x0, right = 0x0)
Node: 'G' (ptr = 0x7fc63fc027f0, left = 0x0, right = 0x7fc63fc02830)
Node: 'H' (ptr = 0x7fc63fc02830, left = 0x0, right = 0x7fc63fc02850)
Node: 'I' (ptr = 0x7fc63fc02850, left = 0x0, right = 0x0)
Added I: end
F B G A C H D I E The queue is empty!
,以使代码更简单:
count()