gpt4 book ai didi

javascript - 如何在angularjs中访问ng repeat之外的项目?

转载 作者:行者123 更新时间:2023-11-30 10:00:33 25 4
gpt4 key购买 nike

我正在尝试显示来自 ng-repeat 的项目的数据(导致 ng-repeat 的项目数始终是一个,因为我按代码搜索)。

<script>
var pdvApp = angular.module('pdvApp', []);

pdvApp.controller('pdvController', function pdvController($scope) {
$scope.itens = [
{code: 1, name: 'Skittles', quantity: 5, price: 2.35},
{code: 2, name: 'M&Ms', quantity: 55, price: 1.29},
{code: 3, name: 'Gummy Bears', quantity: 5, price: 22.59},
{code: 4, name: 'Snickers', quantity: 500, price: 0.89},
{code: 10, name: 'KitKat', quantity: 500, price: 0.89},
];
});
</script>

....(在 HTML 中)

<input type="number" class="form-control input-lg" id="search" autofocus="" value="" ng-model="search.code"/>
<div class="col-md-8 form-group">
<div ng-repeat="item in filtered =(items| filter:search:true)">
<span ng-show="filtered.length===1"><input type="text" class="form-control input-lg" id="desc" autofocus="" value="{{item.name}}"/></span>
</div>
<span ng-hide="filtered.length===1"><input type="text" class="form-control input-lg" id="desc" autofocus="" value="{{item.name}}"/></span>
</div>

我希望它能工作(在 ng-repeat block 之后,没有新的 ng-repeat):

Name: 
<div class="form-group">
<input type="text" id="name" ng-model="name" class="form-control input-lg" value="{{item.name}}" readonly=""/>
</div>

最佳答案

我相信您正在寻找Special repeat start and end points这允许你在同一个重复中有兄弟元素(而不是根元素。)

关于javascript - 如何在angularjs中访问ng repeat之外的项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31971571/

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