我试图在我的DOM中获取元素并将它们作为数组返回。它们是嵌套的。我想要量角器返回这样的东西:
{
category_title: "cat1",
items: {item_title: "item1"}, {item_title: "item2"}
},
{
category_title: "cat2",
items: {item_title: "item1"}, {item_title: "item2"}
}
DOM:
<div ng-repeat="category in categories">
<div id="category-title">{{ category.title }} </div>
<div ng-repeat="item in category.items">
<div id="item-title">{{ item.title }} </div>
</div>
</div>
这就是我在量角器中的尝试:
return element.all(by.repeater("category in categories")).map(function(elm) {
var category_title = elm.element(by.id('category-title')).getText(),
var t = {
category_title: category_title,
dimensions: {}
};
// After this part, I'm lost...
return elm.all(by.repeater("item in category.items")).map(function(elm) {
return {
category_title: category_title,
dimension: elm.element(by.id('item-title')).getText(),
}
});
});
答案 0 :(得分:0)
这似乎有效,但我不能100%确定它是否正确
return element.all(by.repeater("category in categories")).map(function(elm) {
return {
category_title: elm.element(by.id('category-title')).getText(),
items: elm.all(by.id("item-title")).getText()
}
})