简体   繁体   中英

dynamic select_tag?

I have posts that gets filtered based on location, category and tags, so I have 3 select_tag that chooses the filtering. The items in the select_tag are of this form name (num) where num is the number of posts that satisfy the filter. As you can see if I have Boston (20) for location and Computer (10) for category, there's no way to tell how many results I will come up with if I specify both Boston and Computer. I was wondering if after I choose Boston (20), the select_tags will update itself so Computer (10) might become Computer (5) and so on.

看看这个Railscast 情节

You'll need to use an ajax call to get either the data in the new select tag via JSON or a completely new select tag rendered as HTML that you can use to replace your current select tag. If you are using jQuery you can probably do something like this:

$('.category').load('/categories/select?location='+$('.location').value());

Where select would be an action on CategoriesController that would generate the HTML for the new category select tag.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM