【发布时间】:2016-10-31 20:45:50
【问题描述】:
我在为下面的 row.map 函数中的每一行拉取一个子 div ID 时遇到问题。
换句话说,对于我迭代的每个行元素,我想拉rowId attrib:
<div id="rowId_21">
这是一个 Html sn-p:
<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">
<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')]"),
但似乎两者都不起作用。
建议赞赏...
鲍勃
【问题讨论】: