我有一个包含以下内容的json对象:
{
"-database": "URL",
"-id": "Veveve",
"value": [
"*.serse.pl/*",
"*.qq.serser/*",
]
}
我的问题是: 接受克林特的json并将我的json对象保存在myjson Virabel中 我如何在ba-panel-title =""设置" -id" 值?
**当我myjson.-id
时,我得到了一个未定义的参数
谢谢
答案 0 :(得分:1)
使用 myjson["-id"]
console.log(myjson["-id"]);
样本
var myjson = {
"-database": "URL",
"-id": "Veveve",
"value": [
".serse.pl/",
".qq.serser/"
]
};
console.log(myjson["-id"]);
答案 1 :(得分:0)
您可以从ng-repeat
的对象中提取键和值。这是一个简单的演示:
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.myjson = {
"-database": "URL",
"-id": "Veveve",
"value": [
".serse.pl/",
".qq.serser/"
]
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
<div ng-repeat="(key,val) in myjson">
<div>KEY: {{key}} | VALUE: {{val}}</div>
</div>
</div>
如果你有一个对象数组:
,这是一个例子
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.myjson = [{
"-database": "URL",
"-id": "Veveve",
"value": [
".serse.pl/",
".qq.serser/"
]
}, {
"-database": "URL2",
"-id": "Wiwiwi",
"value": [
".qq.serser/"
]
}, {
"-database": "URL3",
"-id": "Uauaua",
"value": [
".serse.pl/"
]
}];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
<div ng-repeat="i in myjson">
<div ng-repeat="(key,val) in i">
<div>KEY: {{key}} | VALUE: {{val}}</div>
</div>
<br>
</div>
</div>