如何用量角器+角来获得迭代器的索引/键? [英] How to get iterator index/key using protractor + angular?

查看:134
本文介绍了如何用量角器+角来获得迭代器的索引/键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在被转发寻找元素时访问迭代器的索引/键的方式?

  protractor.By.repeater((ID,CAT)的宠物)

在这种情况下,我希望得到进入猫的身份证。 标识是不是显示为表中的值的一列,它是用于导航的 NG-点击=转到('/宠物/'+ cat.id)。有一个在HTML中没有绑定,如 {{ID}} {{} cat.id} 这样做以下内容:

  ptor.findElements(protractor.By.repeater((ID,CAT)的宠物)。列('cat.id'))

返回一个空元素: []

我也,失败,尝试做这样的事情:

  ptor.findElement(protractor.By.repeater((ID,CAT)的宠物)。行(0).column('cat.id'))

什么是访问的具体指标的正确方式?

这是一个被JMR答案的非缩短语法:


ptor.findElements(protractor.By.repeater('(ID,CAT)的宠物'))。然后(功能(ARR){
    ARR [0]评估('cat.id'),然后(函数(ID){
        的console.log(ID);
    });
});


解决方案

您正在寻找的东西进行评估,这不是在页面上,这样的行和列的方法是行不通的。如果你只需要使用中继器,你会得到所有行的数组。然后,您可以使用评估命令该元素的背景下,以评估前角pressions。例如(使用缩短的语法),

  element.all(by.repeater('(ID,CAT)的宠物'))。然后(功能(ARR){
  ARR [0]评估('cat.id'); //这是解析为ID的承诺。
});

Is there a way to access the iterator index/key when looking for elements by repeater?

protractor.By.repeater("(id,cat) in pets")

In this case I'm looking to get access to "id" of the cat. The "id" is NOT one of the columns displayed as a value in the table, it is used for navigation as ng-click="goto('/pets/'+cat.id)". There is no binding in the HTML such as {{id}} or {{cat.id}} so doing the following:

ptor.findElements(protractor.By.repeater("(id,cat) in pets").column('cat.id'))

returns an empty element: []

I've also, unsuccessfully, tried doing something like:

ptor.findElement(protractor.By.repeater("(id,cat) in pets").row(0).column('cat.id'))

What is the correct way to access that specific index?

Here's the non-shortened syntax of the answer by Jmr:

ptor.findElements(protractor.By.repeater('(id, cat) in pets')).then(function (arr) {
    arr[0].evaluate('cat.id').then(function (id) {
        console.log(id);
    }); 
});

解决方案

You're looking to evaluate something that's not on the page, so the 'row' and 'column' methods won't work. If you just use the repeater, you will get an array of all of the rows. You can then use the evaluate command to evaluate Angular expressions in the context of that element. For example (using shortened syntax),

element.all(by.repeater('(id, cat) in pets')).then(function(arr) {
  arr[0].evaluate('cat.id'); // This is a promise which resolves to the id.
});

这篇关于如何用量角器+角来获得迭代器的索引/键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆