Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/414.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我不知道如何使用AngularJS获取JSON文件中的子数据_Javascript_Json_Angularjs - Fatal编程技术网

Javascript 我不知道如何使用AngularJS获取JSON文件中的子数据

Javascript 我不知道如何使用AngularJS获取JSON文件中的子数据,javascript,json,angularjs,Javascript,Json,Angularjs,我有这个JSON文件: {"__v":4,"_id":"53dbeedb1a6550ee08c55c05","name":"Quatro formaggi","ingredients":["53c791b6e4b04af47f662f98","53c791b6e4b04af47f662f98","53c791b6e4b04af47f662f98","53c791b6e4b04af47f662f98"]} 我要所有的配料。如果我写: {{pizza.ingredients}} 我得到: ["5

我有这个JSON文件:

{"__v":4,"_id":"53dbeedb1a6550ee08c55c05","name":"Quatro formaggi","ingredients":["53c791b6e4b04af47f662f98","53c791b6e4b04af47f662f98","53c791b6e4b04af47f662f98","53c791b6e4b04af47f662f98"]}
我要所有的配料。如果我写:

{{pizza.ingredients}}
我得到:

["53c791b6e4b04af47f662f98","53c791b6e4b04af47f662f98","53c791b6e4b04af47f662f98","53c791b6e4b04af47f662f98"]
如果我这样写:

{{pizza.ingredients.1}}
我明白了:

53c791b6e4b04af47f662f98
但我想要一个循环,我可以得到这样的结果:

1- 53c791b6e4b04af47f662f98
2- 53c79214e4b04af47f662f9d
3- 53c7925ae4b04af47f662fa0

如何使用AngularJS实现这一点?

我不会给出精确的输出,但经过一些修改后,您应该会得到它

像贝娄那样做

<div ng-repeat="piz in pizza">
   {{$index+1}}--  {{piz.ingredients.0}}
</div>
这是每个InCredit的第一个元素


对不起,我弄糊涂了,我把所有的比萨饼都复制到了JSON文件中。但是 现在我用一个比萨饼更改了JSON文件,我想得到 一份比萨饼的配料。如果我写这句话:ing比萨饼 获取此错误:错误:[ngRepeat:dups] ‌​p1=字符串%3A53c791b6e4b04af47f662f98


@那是因为你不能有重复的 repeater,请参见这里的docs.angularjs.org/error/ngRepeat/dupes–

你说得对@Mritunjay

更正的代码为:

<div>
    <p>{{pizza.name}}</p>   
        <div ng-repeat="ing in pizza.ingredients track by $index">
            <p>{{ing}}</p>
        </div>      
</div>

我的问题在

中解释了,你能创建一个提琴吗?所有的建议都对mesorry有好处,我把所有的比萨饼都复制到了JSON文件中。但是现在我用一个比萨饼更改了JSON文件,我想用一个比萨饼来获取配料。如果我写这个:ing pizza.components,我会得到这个错误:error:[ngRepeat:dups]http://errors.angularjs.org/1.2.19/ngRepeat/dupes?p0=i%20in%20pizza.ingredients&p1=string%3A53c791b6e4b04af47f662f98 v/@Dominuskernel-ohhhh这是因为在中继器中不能有重复项,请看这里@Dominuskernel,您应该接受答案,或者如果答案有帮助,至少向上投票
<div>
    <p>{{pizza.name}}</p>   
        <div ng-repeat="ing in pizza.ingredients track by $index">
            <p>{{ing}}</p>
        </div>      
</div>