1
我有问题拉动孩子div
ID在row.map
函数下面的每一行。使用量角器选择子div ID
换句话说,对于每一行元素我重复,我想拉rowId
ATTRIB:
<div id="rowId_21">
下面是一个HTML片段:
<div ng-repeat="row in vm.sourceData.data" ng-init="thatRow=$index">
<div id="rowId_21" ng-class-odd="'row-2'" ng-class-even="'row-3'" >
<div ng-repeat="column in vm.sourceData.columns" >
<div ng-if="row[column.field].length !== 0" class="ng-scope highlight21"> \t
\t <span ng-bind-html="row[column.field] | changeNegToPrenFormat" vm.highlightedrow="" class="ng-binding">
Sales
</span>
</div>
</div>
</div>
</div>
<div ng-repeat="row in vm.sourceData.data" ng-init="thatRow=$index">
<div id="rowId_22" ng-class-odd="'row-2'" ng-class-even="'row-3'" ng-class="vm.hideRow(row)" class="row-3 height-auto">
<!-- ... -->
</div>
</div>
我开始拉动rows
对象,然后我重复它们:
// pulls the data rows
var selDataRows = '.grid-wrapper.fluid-wrapper';
var rows = element(by.css(selDataRows)).all(by.repeater('row in vm.sourceData.data'));
rows.map(function (row, idx) {
//var thisRowId = row.element(by.css('div[id^="rowId_"]')); // *** RETURNS NULL
var thisRowId = row.all(by.xpath("descendant::div[starts-with(@id, 'rowId')]"));
thisRowId.getText().then(function(txt){
// RETURNS A VERY LONG ID: [ '7\n4\n41\n113\n3.3\n(34)\n(1.1)\n7...]
console.log('--- Curr Div ID: ', txt);
});
}).
then(function(){
console.log('*** Rows.Map Done.');
});
我认为这将拉动第一子ID(即https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors):
by.css('div[id^="rowId_"]')
,
或者可能是这样的:
by.xpath("descendant::div[starts-with(@id, 'rowId')]")
,
但是似乎都不奏效。
咨询赞赏...
鲍勃
这位朋友你好,和thnk你的回应。原来我需要映射函数中的rowId;但是,看起来像我通过使用'thisRowId.getText()'而不是'getAttribute(“id”)''发生了错误。我会在早上重新测试第一件事。谢谢 ! –
@ bob.mazzo明白了,是的,这应该有所帮助。顺便说一下,如果以后不需要id数组,那么看看'each()'是否比map()'更适合工作。谢谢,让我们在城市里喝一两杯啤酒吧! (如果有兴趣,请通过linkedin ping我!) – alecxe
我正在考虑'.each()',但我完全忘记发生了什么。我会重新审视这个想法。 +1 –