简体   繁体   English

角ng-click排序

[英]Angular ng-click ordering

New to Angular, so far loving it. Angular的新手,到目前为止很喜欢它。 I've come so far in creating a list of thumbnails. 到目前为止,我已经创建了一个缩略图列表。 I've added 3 sort buttons order the thumbnails by 3 different data values. 我添加了3个排序按钮,通过3个不同的数据值对缩略图进行排序。 All works great but to make it a little more less confusing for the user I would like to reset/turn of ordering for one data set when another order button is clicked. 一切都很好,但是为了让用户更轻松一些,我想在单击另一个订购按钮时重置/打开一个数据集的订购。 EG - https://jsfiddle.net/5wayfc4z/ EG- https://jsfiddle.net/5wayfc4z/

From the fiddle you will notice when you click on country its becomes orederd by "country" when you then click on "az" it will sort the data by attraction but the "country" sorting will be still showing - to turn this off I need to click on country again. 从小提琴中,您会注意到,当您单击“国家/地区”时,它会变成“国家/地区”;当您单击“ az”时,它将按吸引力对数据进行排序,但仍会显示“国家/地区”排序-请关闭此功能以再次单击国家。 I only want to sort one field one at a time if that makes sense? 如果可以的话,我只想一次对一个字段进行排序?

            <div id="buttons" class="row">
            <div class="col-sm-6 col-md-4">
                    <a href="" id="1" ng-click="order('attraction');" class="btn btn-primary btn-block active">a-z</a>

            </div>
            <div class="col-sm-6 col-md-4">
                    <a href="" id="2" ng-click="order('country'); villa = !villa" class="btn btn-primary btn-block inactive">Country/State</a>

            </div>
            <div class="col-sm-6 col-md-4">
                    <a href="" id="3" ng-click="order('category')" class="btn btn-primary btn-block inactive">type of attraction</a>

            </div>
            </div>

            <article>

                        <div class="row">

                <div ng-repeat="selfieObj in sticks | filter:searchAttraction | orderBy:predicate:reverse">
                <div class="col-xs-12" ng-show="newGrouping($parent.sticks, 'country', $index);">
            <h2 ng-show="villa">{{selfieObj.country}}</h2>
            </div>

            <div class="col-sm-6 col-md-3">
                    <div class="thumbnail">
                        <img ng-src="{{selfieObj.mainImage}}" alt="{{selfieObj.attraction}}" title="{{selfieObj.attraction}}">
                        <div class="caption">
                            <h3>{{selfieObj.attraction}}</h3>
                            <p class="text-center">
                                {{selfieObj.answer}} {{selfieObj.info}}
                            </p>
                        </div>
                    </div>
                    </div>
                </div>
            </div>
            </article>

EDIT: 编辑:

https://jsfiddle.net/5wayfc4z/ new fiddle to take away the styling so it does not confuse. https://jsfiddle.net/5wayfc4z/新的提琴手可以删除样式,因此不会造成混淆。

To see my issue click on "country/state" - you will see the filter work by sorting by country and adding the country name. 要查看我的问题,请点击“国家/州”-您将通过按国家/地区排序并添加国家/地区名称来查看过滤器的工作。 Then click on "az" this works BUT you will notice the filter for "country/state" is still in effect - in order to remove the "country/state" you have to click that filter button again. 然后单击“ az”,这将起作用,但是您会注意到“国家/州”的过滤器仍然有效-要删除“国家/州”,您必须再次单击该过滤器按钮。

The sorting seems to work fine in your fiddle, so is this just a visual issue? 排序似乎对您的提琴效果很好,所以这只是视觉问题吗? Just remove the initial states from the buttons: 只需从按钮中删除初始状态:

class="btn btn-primary btn-block"

instead of adding active or inactive by default. 而不是默认情况下添加activeinactive

I have forked your fiddle with the fix: fiddle 我已付出你的小提琴与修复: 提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM