Ранее я пытался извлечь информацию из возврата JSON, откуда мне нужно извлечь значение ключа в виде массива: -
$scope.jsonObj = {
"stylesheet": {
"attribute-set": [
{
"attribute": {
"_name": "text-align",
"__prefix": "xsl",
"__text": "center"
},
"_name": "__frontmatter",
"__prefix": "xsl"
},
{
"attribute": [
{
"_name": "space-before",
"__prefix": "xsl",
"__text": "80mm"
},
{
"_name": "line-height",
"__prefix": "xsl",
"__text": "140%"
}
],
"_name": "__frontmatter__title",
"_use-attribute-sets": "common.title",
"__prefix": "xsl"
}
],
"_xmlns:xsl": "http://www.w3.org/1999/XSL/Transform",
"_xmlns:fo": "http://www.w3.org/1999/XSL/Format",
"_version": "2.0",
"__prefix": "xsl"
}
};
$scope.textvalue =$scope.jsonObj.stylesheet['attribute-set']
.map(x => {
if (Array.isArray(x.attribute))
return x.attribute.map(y => y['__text']);
else
return [x.attribute['__text']];
})
.reduce((accu, cur) => accu.concat(...cur), []);
console.log($scope.textvalue);
Из этого я получаю массив: - $scope.textvalue=["center", "80mm","140%"]
Итак, теперь я обновляю массив из моего представления и сохраняю одно и то же значение при клике в том же объекте $scope.textvalue
.
Мне нужно обновить textvalue
обратно до объекта JSON $scope.jsonObj
.
Как сопоставить обновленный массив с тем же __text
значением jsonObj
объекта?