在 angular js 的 ng-init 中添加多维对象

Add multi dimension object in ng-init in angular js

我想在 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>

但是当我像这样添加时然后显示这个错误

"Error: [$parse:syntax] Syntax Error: Token 'Carrara' is unexpected, expecting [}] at column 1754 of the expression [object("

那怎么办....

提前致谢...

你的对象结构有误。试试这个

 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