我想在ng-init中添加多维对象,如
object({
friends:[
{name:John,phone:555-1276},
{name:Mary,phone:800-BIG-MARY},
{name:Mike,phone:555-4321},
{name:Adam,phone:555-5678},
{name:Julie,phone:555-8765},
{name:Juliette,phone:555-5678}
],
relative:[
{name:Afaq,phone:555-1276},
{name:Mary,phone:800-BIG-MARY},
{name:Mike,phone:555-4321},
{name:Adam,phone:555-5678},
{name:Julie,phone:555-8765},
{name:Juliette,phone:555-5678}
]
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
但是当我像这样添加相同时,请告诉我这个错误
“错误:[$ parse:syntax]语法错误:Token'Carrara'是意外的,期待[}]在表达式1754的第1754行[object(”
那该怎么做....
提前致谢...
答案 0 :(得分:0)
您的对象结构错误。试试这个
var x = {
"parent": {
"friends": [{
"name": "John",
"phone": "555 - 1276"
},
{
"name": "John",
"phone": "555 - 1276"
},
{
"name": "John",
"phone": "555 - 1276"
},
{
"name": "John",
"phone": "555 - 1276"
},
{
"name": "John",
"phone": "555 - 1276"
},
{
"name": "John",
"phone": "555 - 1276"
}
],
"relative": [{
"name": "John",
"phone": "555 - 1276"
},
{
"name": "John",
"phone": "555 - 1276"
},
{
"name": "John",
"phone": "555 - 1276"
},
{
"name": "John",
"phone": "555 - 1276"
},
{
"name": "John",
"phone": "555 - 1276"
},
{
"name": "John",
"phone": "555 - 1276"
}
]
}
}
console.log(x);
您始终可以使用Json lint来验证您的json