I have list of dicts that contains another list in one of fields. I want to "flatten" that list, so it gives me every subelement with one field (or some fields) from parent copied into it. Example:
Source data:
[
{
"name": "A",
"foo": "x",
"bar": 1,
"subelements": [
{
"baz": "xyz",
"foobar": "abc"
},
{
"baz": "zzz",
"foobar": "def"
}
]
},
{
"name": "B",
"foo": "Y",
"bar": 4,
"subelements": [
{
"baz": "yyy",
"foobar": "aaa"
},
{
"baz": "xxx",
"foobar": "bbb"
},
{
"baz": "www",
"foobar": "bbb"
}
]
}
]
Expected result:
[
{
"baz": "xyz",
"foobar": "abc",
"foo": "x"
},
{
"baz": "zzz",
"foobar": "def",
"foo": "x"
},
{
"baz": "yyy",
"foobar": "aaa",
"foo": "Y"
},
{
"baz": "xxx",
"foobar": "bbb",
"foo": "Y"
},
{
"baz": "www",
"foobar": "bbb",
"foo": "Y"
}
]
If You want to get list only children elements with id or class, avoiding elements without id/class, You can use document. getElementById('container'). querySelectorAll('[id],[class]'); ... querySelectorAll('[id],[class]') will "grab" only elements with id and/or class.
Find child elements (protractor chaining locators)First we need to find the parent element then using the parent element we find the child element and perform operation on it. var parent = element(by.id('get-input')); var child = parent. element(by. className('form-group')); child.
This is not currently possible to do without parent node reference. Parent node access is still listed as a feature request
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With