Angularjs 使用选择值过滤列表数据

Angularjs filter list data using select value

本文关键字:过滤 列表 数据 选择 Angularjs      更新时间:2023-09-26

我有以下格式的json数据:{ "id": "mypics-1", "imageThumbUrl": "img/small/1.jpg", "imageUrl": "img/large/1.jpg", "名称": "1.jpg", "类型": "imgage"}, { "id": "mypics-2", "imageThumbUrl": "img/small/2.jpg", "imageUrl": "img/large/2.jpg", "名称": "2.jpg", "类型":"图像"}

如果用户从下拉列表中选择一个值,我需要在类型基础上过滤图像列表。我的代码如下。我尝试了很多方法,但它没有过滤数据,而是清空了列表。

                        <select ng-model="showGenre">
                            <option value=" " selected>All</option>
                            <option ng-repeat="type in ImageTypes" value="{{type.name}}">{{type.name}}</option>
                        </select>
                        <div class="myPicsDivCls">
                            <ul id="carousel2" class="elastislide-list">
                                <li ng-repeat="ImageFile in ImageFiles | filter: {type:showGenre}">
                                    <a>
                                        <img ng-src="{{ImageFile.imageThumbUrl}}" data-echo="{{ImageFile.imageThumbUrl}}" alt="image06" />
                                    </a>
                                </li>
                            </ul>
                        </div> 

试试

<li ng-repeat="ImageFile in ImageFiles | filter: showGenre">

//----------编辑-----------//尝试

<li ng-repeat="ImageFile in ImageFiles | showGenre">

//----------编辑----------------//改变

<option value=" " selected>All</option>

 <option value="" selected>All</option>

我认为是由于