jquery排序json对象
我在 jquery 中有下面的 Json 对象,我用它来填充 jquery 网格。
现在我需要根据“performanceName”对其进行排序。
请建议我如何实现这一目标。请我知道同样的问题已发布 100 次,但我仍然努力在下面的 json 上实现排序
{
"callback": "",
"html": "",
"message": [
""
],
"responseData": [
{
"collectionTitleId": 1107861,
"collectionTitleIdSpecified": true,
"performanceField": {
"addedDate": "6/16/2011 11:11:10 PM",
"artist": "Corbis",
"performanceName": "Showcase Graphic 003 - Anime Girl Purple",
"performanceType": "Graphic",
"provider": "DMSP Dynamic Digital"
},
"sortOrder": "01"
},
{
"collectionTitleId": 1113513,
"collectionTitleIdSpecified": true,
"performanceField": {
"addedDate": "5/25/2011 9:27:39 AM",
"artist": "Beloved",
"performanceName": "Hating On Your Feet (Verse)",
"performanceType": "LabelTone",
"provider": "p1"
},
"sortOrder": "02"
}
],
"status": [
"Success"
]
}
提前致谢
I have the below Json object in jquery which i m using to fill a jquery grid.
Now i need to sort it on the basis of "performanceName".
Please advice how i can achieve this. Please i knw same kinda question is posted 100 times but still i m struggling to implement sorting on below json
{
"callback": "",
"html": "",
"message": [
""
],
"responseData": [
{
"collectionTitleId": 1107861,
"collectionTitleIdSpecified": true,
"performanceField": {
"addedDate": "6/16/2011 11:11:10 PM",
"artist": "Corbis",
"performanceName": "Showcase Graphic 003 - Anime Girl Purple",
"performanceType": "Graphic",
"provider": "DMSP Dynamic Digital"
},
"sortOrder": "01"
},
{
"collectionTitleId": 1113513,
"collectionTitleIdSpecified": true,
"performanceField": {
"addedDate": "5/25/2011 9:27:39 AM",
"artist": "Beloved",
"performanceName": "Hating On Your Feet (Verse)",
"performanceType": "LabelTone",
"provider": "p1"
},
"sortOrder": "02"
}
],
"status": [
"Success"
]
}
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 Array.prototype.sort 就地对数组进行排序。如果没有任何参数,这会尝试按字母顺序对元素进行排序,但您可以传入比较函数。该函数接收两个参数,并应返回小于 0、0 或大于 0 的值,以定义参数 1 与参数 2 的关系。
您的排序函数应如下所示:
localeCompare< /code> 为我们完成了比较字符串的艰苦工作。
排序
方法localeCompare
方法You can use
Array.prototype.sort
to in-place sort an array. Without any arguments, this attempts to sort elements alphabetically, but you can pass in a comparing function instead. This function receives two arguments and should return less than 0, 0 or greater than 0 to define where argument 1 should be in relation to argument 2.Your sorting function should look something like this:
localeCompare
does the hard work of comparing the strings for us.sort
methodlocaleCompare
method