我已经使用 Angular JS 成功实现了类型提前 codepen
.
现在我的数据是动态的,所以我想创建自己的 json,它应该如下所示:
$scope.states = [
{
name: "ABCD",
id: "AB"
},
{
name: "XYZ",
id: "XY"
},
{
name: "OPQR",
id: "OP"
},
{
name: "LMNO",
id: "LM"
},
{
name: "KLM",
id: "KL"
}
];
如何像上面那样创建 json 并存储在 $scope 变量中,以便我可以分别使用名称和 id 访问它。
请帮助我...!!
最佳答案
我现在自己捐献,因为我得到的有点晚了。
解决方案是我将数据推错了,我已经解决了它,如下所示:
$scope.states.push({
name: "string",
id: int,
});
我明白了。
关于javascript - 如何创建以下类型的 json,该类型将在使用 Angular JS 进行类型提前时有用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37154666/