如何使用NSSortDescriptor对NSMutableArray进行排序?(How to sort a NSMutableArray using NSSortDescriptor?)
我正在从
JSON
webservice解析数据,然后使用以下代码按价格,日期,折扣等对数据进行排序。这是我用来对数据进行排序的代码:
-(void)priceSort:(id)sender { NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey: @"price" ascending: YES]; NSMutableArray *sortedArray = (NSMutableArray *)[self.displayItems sortedArrayUsingDescriptors: [NSArray arrayWithObject:sortDescriptor]]; [self setDisplayItems:sortedArray]; [self.tableView reloadData]; }
当我尝试按价格排序时,这种方法很好,但是当我想按照评论数排序时,我似乎无法正确地获取代码:
我用的价格:
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey: @"price" ascending: YES];
但对于评论,我想得到“n”值。 看看它是如何嵌套在输出中的(显示项目mutableArray如下:
"old_price" = 24; price = "9.9"; reviews = { **n = 11;** val = 70; }; "sold_count" = 101;
谢谢你对此有任何帮助:)
I'm parsing data from
JSON
webservice and then using the following code to sort the data by price, date, discount etc.here's the code I'm using to sort the data:
-(void)priceSort:(id)sender { NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey: @"price" ascending: YES]; NSMutableArray *sortedArray = (NSMutableArray *)[self.displayItems sortedArrayUsingDescriptors: [NSArray arrayWithObject:sortDescriptor]]; [self setDisplayItems:sortedArray]; [self.tableView reloadData]; }
this works fine when I'm trying to sort by price, however when I want to sort by number of reviews I can't seem to get the code right:
for price I use:
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey: @"price" ascending: YES];
but for reviews I want to get the "n" value. see how it's nested in the output (of the display Items mutableArray below:
"old_price" = 24; price = "9.9"; reviews = { **n = 11;** val = 70; }; "sold_count" = 101;
thanks for any help on this :)
原文:https://stackoverflow.com/questions/15027377
最满意答案
我终于制作了自己的jQuery插件。 它管理页面交换和文件的ajax加载,在显示每个页面之前和之后触发自定义事件。 收到的评论不超过150行。 不过,我保留了参数传递的东西。
I finally made my own jQuery plugin. It manages the page-swapping and the ajax loading from files, firing custom events before and after each page is shown. Took no more than 150 lines comments included. I kept the parameter-passing stuff out, though.
相关问答
更多-
我认为这是大多数网站在考虑用户今天使用的设备数量以及各自的能力和限制时应该考虑的方向。 重要: 在阅读其余部分之前,请理解这个概念是建立在网络设计基本原理的基础上的。 为了为所有设备和情况设计单页应用程序,它不能作为单页应用程序专门运行。 您必须建立一个基础,可以在基本功能非常有限的浏览器上工作,并根据其设备的功能增强用户体验。 这可能会给你带来更多的工作,但是你将能够满足更大和更多样化的观众,这比将专门为现代桌面或手机浏览器构建的网络应用程序集中在一起更令人印象深刻。 减少加载时间和/或重量 单页应用程序 ...
-
看到这个答案 。 就开发工作而言,过度简化的比较是 多页面应用程序: HTTP请求中包含的用户操作(例如HTTP POST,HTTP GET) 请求被处理,服务器响应HTTP页面 缺点:需要很多页面才能响应每个用户的操作(例如,将项目添加到列表,更新表单数据),而在SPA数据绑定中可以为您更新视图。 其次,Web应用程序负责维护整个页面请求之间的状态。 相反,当浏览器停留在同一页面上时,SPA可以在XHR之间保持其状态,而无需额外的工作。 单页应用程序(SPA): 在客户端和服务器端配置路由 代码“控制器” ...
-
SPA(单页面应用程序)与使用Django或Backbone无关。 您可以在使用Django时编写SPA。 但你也可以使用Backbone和Django。 有关更多信息,请阅读以下帖子: http://sidazad.tumblr.com/post/52201957429/web-2-0-the-switch-to-client-javascript-frameworks http://sidazad.tumblr.com/post/52591790157/the-search-for-the-perfec ...
-
单页应用程序组织(Single Page Application Organization)[2022-05-06]
我建议按功能组织您的应用程序,其中每个功能都是一个Angular模块。 看到这里的例子https://github.com/angular-app/angular-app : + src + admin + users . admin-users-add.js . admin-users-add.tpl.html . admin-users-edit.js . admin-users.edit.tpl.html . admin.js + ... -
如果您选择使用单页概念设计应用程序 - 那么大多数css / js文件只会加载,其他逻辑将使用javascript(模板,调用后端等)完成。单页方法也需要有特定的后端 - 在大多数情况下,存在具有xml,json端点的RESTful服务。例如,当您有单个页面 - 并且您想要获取有关某些(例如)产品的信息时,您需要使用url调用后端 - HTTP:// {后端主机} / API /产品/ 1 和后端应该返回(示例): { "id": 1, "name" : "product1" } 您将使用 ...
-
http://docs.angularjs.org/已经完成了你在这里描述的大部分内容。 Disqus对我们来说效果很好。 随意查看源代码。 一切都在github上。 http://docs.angularjs.org/ already do most of what you described here. Disqus works quite well for us. Feel free to look at the source code. Everything is on github.
-
使用Visual Studio 2013在Sharepoint 2013中创建母版页(Creating a masterpage in Sharepoint 2013 with Visual Studio 2013)[2023-07-22]
我刚刚在链接中测试了解决方案,并为摘要添加了一些更新: 转到母版页库以下载您需要自定义的母版页:SharePointSite / _catalogs / masterpage,例如minimal.master和mininal.html 在visual studio中创建新的空sharepoint项目,添加新模块,添加您下载的主页 自定义模块中的Element.xml,并确保以下链接类似:Module Name =“MasterPages”List =“116”Url =“_ catalogs / maste ... -
单页应用程序开发的库/框架(截至2013年)(Library/Framework for Single Page Application Development (as of 2013))[2022-08-28]
我终于制作了自己的jQuery插件。 它管理页面交换和文件的ajax加载,在显示每个页面之前和之后触发自定义事件。 收到的评论不超过150行。 不过,我保留了参数传递的东西。 I finally made my own jQuery plugin. It manages the page-swapping and the ajax loading from files, firing custom events before and after each page is shown. Took no mor ... -
单页应用程序(Single Page Application)[2023-06-30]
扩展库版本附带了几个updateSite拉链: updateSiteOpenNTF.zip updateSiteOpenNTF-designer.zip updateSiteOpenTNTFExtended.zip updateSiteOpenNTFSamples.zip 确保使用的是updateSiteOpenNTF-designer.zip ,而不是标准的updateSiteOpenNTF.zip。 顾名思义,设计器zip包含专门为Designer设计的extlib内容,例如Single App Wi ... -
是的, Gmail是一个单页应用程序。 这就是加载Gmail之前你看到进度条的原因,因为它从服务器获取所有内容,然后在客户端完成所有渲染,只调用服务器获取数据而不是DOM。 除了Gmail之外,Google Calendar,Google Drive等套件中的其他服务也是单页应用程序。 Yes, Gmail is a single-page application. That is the reason before loading Gmail you see a progress bar, as it f ...