admin管理员组文章数量:1426020
I just started looking at Backbone.js. Now i wan't to create a simple search similar to google where the url updates "on the go". So if you submit a form i want the url to update to .
I appreciate every answer :)
I just started looking at Backbone.js. Now i wan't to create a simple search similar to google where the url updates "on the go". So if you submit a form i want the url to update to http://www.site./#/search/I-searched-for-something.
I appreciate every answer :)
Share Improve this question asked Jul 5, 2011 at 20:02 EmilEmil 151 silver badge5 bronze badges2 Answers
Reset to default 5If I understand the question, you want an arbitrary URL that includes your search term as part of the URL. And I suspect that your problem is you don't see how to do that with the routes
architecture.
Routes are nothing but regular expressions:
var MyController = Backbone.Controller.extend({
routes: {
RegExp('^search/(.*)$'): "handle_search"
},
handle_search: function(search_term) {
search_term = decodeURIComponent(search_term);
/* Do something ajaxy with the search term in the search model,
which in turn triggers the search view to refresh... */
}
});
After that, you would apply a click
handler to the button on the search form (or maybe a keypress==13
manager to the search field itself) that, instead of actually doing anything, just sets window.location.hash = escapeURIComponent($('#search_field').val())
It's roundabout, but it gets the job done. Your URLs will be ugly with all the %XX's in them, but they'll all be bookmarkable, which is the only reason to do something like this.
Emil, I think I have a similar use case to you where users could make selections and then trigger a search. I want that search to be updated in the address bar so it can be bookmarked. To update the address bar, I was planning on using Backbone navigate
For multiple search terms I plan to 1. set them as values in my the collection and then trigger a fetch on the collection 2. ask the collection for the url and update the address bar using navigate.
本文标签: javascriptBackbonejs search with querystringsStack Overflow
版权声明:本文标题:javascript - Backbone.js search with query-strings - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745396089a2656820.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论