如何对 JQuery Handlebar 生成的数据进行排序?
How to Sort data generated from JQuery Handlebar?
我有从 handlebar.js 动态生成的数据。数据填充在 div 中的 div 中。我想根据车把生成的不同属性对该数据进行排序。
我想根据姓名、计算机代码、父亲姓名等进行排序
这是代码
`
{{#each LawyerList}}
<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: </strong>
<span class="ng-binding">{{OfficeContact}}</span>
<span class="color-grey"> | </span>
<strong class="text-danger">Cell No: </strong>
<span class="ng-binding">{{CellNo}}</span>
<span class="color-grey"> | </span>
<strong class="text-danger">Computer Code : </strong>
<span class="ng-binding">{{ComputerCode}}</span>
</p>
<div style="min-height: 20px;" class="list-unstyled">
<div ng-if="!result.contact.affiliation && 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>
`
您可以使用 jQuery 函数 sort() 对结果(从 ajax 返回)进行排序。
例如:
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) } );
我有从 handlebar.js 动态生成的数据。数据填充在 div 中的 div 中。我想根据车把生成的不同属性对该数据进行排序。
我想根据姓名、计算机代码、父亲姓名等进行排序
这是代码
`
{{#each LawyerList}}
<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: </strong>
<span class="ng-binding">{{OfficeContact}}</span>
<span class="color-grey"> | </span>
<strong class="text-danger">Cell No: </strong>
<span class="ng-binding">{{CellNo}}</span>
<span class="color-grey"> | </span>
<strong class="text-danger">Computer Code : </strong>
<span class="ng-binding">{{ComputerCode}}</span>
</p>
<div style="min-height: 20px;" class="list-unstyled">
<div ng-if="!result.contact.affiliation && 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>
`
您可以使用 jQuery 函数 sort() 对结果(从 ajax 返回)进行排序。 例如:
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) } );