gpt4 book ai didi

javascript - AngularJS 按 ID 过滤

转载 作者:行者123 更新时间:2023-11-30 10:01:34 26 4
gpt4 key购买 nike

我有以下来自 PHP 响应的 Json_encode...

[
{"ID":"149","IDusr":"4","aut_more_info":"good","doc_name":"img1838142879.jpeg","doc_type":"jpg"},{"ID":"149","IDusr":"4","aut_more_info":"good","img5733250433.jpeg","doc_type":"jpg"},{"ID":"149","IDusr":"4","aut_more_info":"good","doc_name":"img1230306801.jpg_doc","doc_type":"jpg"}
]

我试过 https://github.com/a8m/angular-filter插入。这是我的代码。

<div ng-repeat="(key, value) in Detail | groupBy: 'ID'">
<div ng-repeat="aut in value">

<div class="item item-avatar bar bar-calm">
<h2>{{aut.name}} {{aut.model}}</h2>
</div>
<div class="item item-avatar">
<img src="../www/img/icon/{{aut.doc_name}}">
</div>
</div>
</div>

正如您从数组中看到的那样,我有相同的 ID,但 doc_name 不同,这意味着我想显示一次 ID,但也应该显示三个图像。我怎样才能做到这一点?

提前致谢...

最佳答案

您的 JSON 中有错误,您缺少属性名称。

Plunker .

angular.module('foo', ['angular.filter'])

.controller('bar', ['$scope', function($scope){


$scope.Detail = [
{
"ID" : "149",
"IDusr" : "4",
"aut_more_info" : "good",
"doc_name" : "img1838142879.jpeg",
"doc_type" : "jpg"
},
{
"ID" :"149",
"IDusr" :"4",
"aut_more_info" :"good",

// you were missing the property name 'doc_name' here...
"doc_name" :"img5733250433.jpeg",
"doc_type" :"jpg"

},
{
"ID" :"149",
"IDusr" :"4",
"aut_more_info" :"good",
"doc_name" :"img1230306801.jpg_doc",
"doc_type" :"jpg"
}
];

}]);

此外,您似乎正在尝试为 JSON 数据中不存在的属性呈现值

<!DOCTYPE html>
<html>

<head>
<link rel="stylesheet" href="style.css">

</head>

<body ng-app="foo">



<div ng-controller="bar">

<div ng-repeat="(key, value) in Detail | groupBy: 'ID'">

<div ng-repeat="aut in value">

<div class="item item-avatar bar bar-calm">

<!-- you don't have properties name or model in your json -->
<h2>{{aut.name}} {{aut.model}}</h2>
</div>

<div class="item item-avatar">
<img src="../www/img/icon/{{aut.doc_name}}">
</div>
</div>
</div>

</div>




<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-filter/0.5.4/angular-filter.js"></script>

<script src="script.js"></script>
</body>

</html>

关于javascript - AngularJS 按 ID 过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31356307/

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