首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何对从JQuery车把生成的数据进行排序?

如何对从JQuery车把生成的数据进行排序?
EN

Stack Overflow用户
提问于 2015-03-27 05:26:01
回答 1查看 193关注 0票数 2

我有从handlebar.js动态生成的数据。数据是填充在div的内部div中。我想根据不同的属性对数据进行排序,这些属性是由车把生成的。

我想根据名字,ComputerCode,父亲的名字等进行排序,这是代码

代码语言:javascript
复制
                                                    {{#each LawyerList}}
代码语言:javascript
复制
        <li id="Record" style="padding-left: 0px;" class="col-lg-12 col-md-7 col-xs-12 no-padding">
            <div class="list-unstyled">
            <div class="row no-margin">
            <div style="width: 90px;" class="no-padding shadow-10 pull-left">
            <div class="crop">
            <span class="helper">
            </span>
            <img src="/Content/images/nopic.jpg" style="width: 85%;" >

            </div>
            </div>
            <div style="padding-left: 20px; padding-right:0; margin-left:90px; min-height: 90px;">
            <a href="/profile/53f45c88dabfaedf43621afb" target="_blank" class="un-styled">
            <h6 class="people-result-name">
                <strong id="name" style="margin-right:5px" class="ng-binding">{{Name}} S/O {{FatherName}} </strong>
            </h6>
            </a>
            <p style="margin-top: 5px; margin-bottom: 5px;" class="font-xs">
            <strong class="text-danger">Office Contact: &nbsp;</strong>
            <span class="ng-binding">{{OfficeContact}}</span>
            <span class="color-grey">&nbsp; | &nbsp;</span>
            <strong class="text-danger">Cell No: &nbsp;</strong>
            <span class="ng-binding">{{CellNo}}</span>
            <span class="color-grey">&nbsp; | &nbsp;</span>
            <strong class="text-danger">Computer Code : &nbsp;</strong>
            <span class="ng-binding">{{ComputerCode}}</span>
            </p>
            <div style="min-height: 20px;" class="list-unstyled">
            <div ng-if="!result.contact.affiliation &amp;&amp; result.org" class="ng-scope">
            <div class="font-xs ng-binding">
            {{OfficeAddress}}
            </div>
            </div>

            <div ng-show="result.homepage" class="ng-hide">
            <div class="font-xs">

            <a href="" class="linked ng-binding"></a>
            </div>
            </div>
            </div>
            <div ng-repeat="tag in result.tags" class="btn-u btn-brd rounded btn-u-default btn-xs btn-interest ng-scope">
            <a href="/search/K-Feldspar" style="color: gray;" class="font-xs ng-binding">Civil</a>
            </div>
            <div ng-repeat="tag in result.tags" class="btn-u btn-brd rounded btn-u-default btn-xs btn-interest ng-scope">
            <a href="/search/Dates" style="color: gray;" class="font-xs ng-binding">Family</a>
            </div>
            <div ng-repeat="tag in result.tags" class="btn-u btn-brd rounded btn-u-default btn-xs btn-interest ng-scope">
            <a href="/search/Miocene" style="color: gray;" class="font-xs ng-binding">Corporate</a>
            </div>
            <div ng-repeat="tag in result.tags" class="btn-u btn-brd rounded btn-u-default btn-xs btn-interest ng-scope">
            <a href="/search/Paleoelevation" style="color: gray;" class="font-xs ng-binding">Criminal</a>
            </div>
            <div ng-repeat="tag in result.tags" class="btn-u btn-brd rounded btn-u-default btn-xs btn-interest ng-scope">
            <a href="/search/Stable Isotopes" style="color: gray;" class="font-xs ng-binding">Terrorist</a>
            </div>
            </div><div style="padding-right:0; padding-left:110px"><hr style="margin-top: 15px; margin-bottom: 15px"></div></div></div>
        </div><!---End of col-lg-12 col-md-7 col-xs-12 no-padding--->
            {{/each}}
        </li>
            <!---End of Record--->
            </script>
    </ul>
            </div>  

`

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-01 05:51:49

您可以使用jQuery函数sort()对结果(从ajax返回)进行排序。例如:

代码语言:javascript
复制
var homes = [
    {
        "h_id": "3",
        "city": "Dallas",
        "state": "TX",
        "zip": "75201",
        "price": "162500"
    }, {
        "h_id": "4",
        "city": "Bevery Hills",
        "state": "CA",
        "zip": "90210",
        "price": "319250"
    }, {
        "h_id": "5",
        "city": "New York",
        "state": "NY",
        "zip": "00010",
        "price": "962500"
    }];
homes.sort(function(a,b) { return parseFloat(a.price) - parseFloat(b.price) } );
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29293859

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档