tag:blogger.com,1999:blog-581197352358126527.post7223082570405546864..comments2024-03-28T00:32:25.959-07:00Comments on japh(r) by Chris Strom: Filtering Backbone.js CollectionsAnonymoushttp://www.blogger.com/profile/00135361916531185929noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-581197352358126527.post-62378420260536007042011-10-08T06:51:09.837-07:002011-10-08T06:51:09.837-07:00@nick Good stuff -- will give that a try. It didn&...@nick Good stuff -- will give that a try. It didn't occur to me that URL could be a function. <br /><br />@breun Thanks for the tip! It probably doesn't make much of a difference with my tiny database (18 documents total), but I will keep that in mind when I get around to scaling.Anonymoushttps://www.blogger.com/profile/00135361916531185929noreply@blogger.comtag:blogger.com,1999:blog-581197352358126527.post-2524911546614398662011-10-08T03:42:35.373-07:002011-10-08T03:42:35.373-07:00I generally don't emit the complete doc as the...I generally don't emit the complete doc as the value in a CouchDB view map function. Instead of 'emit(doc.startDate.subStr(0, 7), doc);' I'd use 'emit(doc.startDate.subStr(0, 7), null);' and query the view using ?include_docs=true.<br /><br />This is a performance versus storage trade-off. Views will be much smaller if you don't emit the doc as the value, but view queries will be a bit faster if you have the doc stored in the view index.breunhttps://www.blogger.com/profile/11076354498835513366noreply@blogger.comtag:blogger.com,1999:blog-581197352358126527.post-80050281284219802062011-10-07T21:22:36.659-07:002011-10-07T21:22:36.659-07:00There is an alternative to this that makes the col...There is an alternative to this that makes the collection more resilient: url as a function.<br /><br />Because you're setting the date via the fetch, any other call to fetch would override what you set. Alternatively:<br /><br /><br />var appointments = new Collections.Appointments({date: year_and_month});<br /><br />Then in the constructor:<br /><br />this.year_and_month = options.year_and_month<br /><br />Then define:<br /><br />url: function() {<br /> return '/appointments/'+year_and_month<br />}<br />setDate: function(y_m) {<br /> this.year_and_month = y_m;<br /> this.fetch;<br />}<br /><br />Then at any time you can do fetch() and it will refresh the current month, or you can do setDate('2011-11') to change the month.<br /><br />This way you don't have to litter your app with fetch statements, and also when you create a new event you already know the month :-)Anonymoushttps://www.blogger.com/profile/14680901673800390862noreply@blogger.com