gpt4 book ai didi

javascript - 如何从 Angular JS ng-repeat 中的数组访问第一个值

转载 作者:数据小太阳 更新时间:2023-10-29 04:00:13 25 4
gpt4 key购买 nike

这是数组

["236.jpg","239.jpg","294.jpg","748.jpg","157.jpg","446.jpg","871.jpg","778.jpg"]

我要访问

"236.jpg"

.下面是我用来获取顶部数组的代码。现在我如何使用下面的代码获取第一个项目?

<tr ng-repeat="x in p">
<td>
{{ x.images }}
</td>
</tr>

请帮我找出解决方案。

这里是完整代码

{"info":[{"id":"11","name":"brown","description":"fasdfasd","size":"fasdf","color":"5a72fb","created_at":"2015-09-08 22:33:33","updated_at":"2015-09-08 22:33:33","images":"[\"236.jpg\",\"239.jpg\",\"294.jpg\",\"748.jpg\",\"157.jpg\",\"446.jpg\",\"871.jpg\",\"778.jpg\"]"},{"id":"13","name":"fasdf","description":"asdfghjkl","size":"fasdf","color":"5a72fb","created_at":"2015-09-09 11:48:31","updated_at":"2015-09-09 11:48:31","images":"[\"910.jpg\",\"504.jpg\",\"784.jpg\"]"}]}


angular.module('myApp', []).controller('myCtrl', function($scope, $http){
$http.get('test').success(function (data){
$scope.p = angular.fromJson(data);
console.log(angular.fromJson(data));
});
});

<tbody ng-controller="myCtrl">
<tr ng-repeat="x in p">
<td ng-if="x.images ">
{{ x.images | limitTo:$index }}
</td>
<td>{{ x.size }}</td>
</tr>
</tbody>

现在请帮我提供完整的代码。谢谢。

最佳答案

只需执行以下操作即可:

<td>
{{p[0]}}
</td>

关于javascript - 如何从 Angular JS ng-repeat 中的数组访问第一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32487418/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com