我对JSON的嵌套结构有些困惑。我正在尝试对几乎没有错误的JSON密钥进行ng-repeat。
我正在将XSL转换为成功发生的JSON。现在,我要访问该JSON以编辑字段。
转换后的我的JSON:-
{
"stylesheet": {
"attribute-set": [
{
"attribute": {
"_name": "text-align",
"__prefix": "xsl",
"__text": "center"
},
"_name": "__frontmatter",
"__prefix": "xsl"
},
{
"attribute": [
{
"_name": "space-before",
"__prefix": "xsl",
"__text": "80mm"
},
{
"_name": "space-before.conditionality",
"__prefix": "xsl",
"__text": "retain"
},
{
"_name": "font-size",
"__prefix": "xsl",
"__text": "22pt"
},
{
"_name": "font-weight",
"__prefix": "xsl",
"__text": "bold"
},
{
"_name": "line-height",
"__prefix": "xsl",
"__text": "140%"
}
],
"_name": "__frontmatter__title",
"_use-attribute-sets": "common.title",
"__prefix": "xsl"
},
{
"attribute": [
{
"_name": "font-size",
"__prefix": "xsl",
"__text": "18pt"
},
{
"_name": "font-weight",
"__prefix": "xsl",
"__text": "bold"
},
{
"_name": "line-height",
"__prefix": "xsl",
"__text": "140%"
}
],
"_name": "__frontmatter__subtitle",
"_use-attribute-sets": "common.title",
"__prefix": "xsl"
},
{
"attribute": [
{
"_name": "space-before",
"__prefix": "xsl",
"__text": "36pt"
},
{
"_name": "font-size",
"__prefix": "xsl",
"__text": "11pt"
},
{
"_name": "font-weight",
"__prefix": "xsl",
"__text": "bold"
},
{
"_name": "line-height",
"__prefix": "xsl",
"__text": "normal"
}
],
"_name": "__frontmatter__owner",
"_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"
}
}
我要访问此部分:-
"attribute": {
"_name": "text-align",
"__prefix": "xsl",
"__text": "center"
}
通过阅读带有显示标签的键_name
来 ng-repeat 文本框,例如:文本框中的值和输入值必须更改__text
值。
我的控制器:-
$scope.xml = '';
$http({
method: 'GET',
url: 'test.xsl',
timeout: 10000,
transformResponse: function(data) {
//string -> XML document object
$scope.xml = data;
}
}).success(function(data, status, headers, config) {
//console.dir(data);
$scope.x2js = new X2JS();
$scope.xmlText = $scope.xml;
$scope.jsonObj = $scope.x2js.xml_str2json($scope.xmlText);
console.log($scope.jsonObj);
angular.forEach($scope.jsonObj, function(value, key) {
console.log(value.attribute-set); ** // here I am getting ReferenceError: set is not defined in console**
angular.forEach(value.attribute, function(v, k) {
console.log(v._name);
console.log(v.__text);
});
});
}).error(function(data, status, headers, config) {
$window.alert('didnt passed.');
});
我的HTML视图:-
<form method="post" id="contactFrm" name="contactFrm">
<div ng-repeat="attrs in jsonObj.attribute._name">
<input type=" text " required=" " placeholder=" " value=" " name="values " class="txt " ng-model="spaceb " ng-repeat="(key, val) in attrs>
</div>
</form>
那么我如何才能获取"_name"
作为嵌套值以在文本字段中使用ng-repeat?