开发者

Jquery: on filtering list(working), how to: make case insensitive, count number of keywords selected for each LI, and

http://jsf开发者_如何学编程iddle.net/nicktheandroid/ape5U/

There's 2 or 3 things I need help with, if you can help me/guide me in the right direction on any of them, that would be great.

1) make script case-insensitive

2) When typing 'holy' it will show 'angels, jesus, holy spirit', when adding the word 'spirit' it will only show 'holy spirit'. I want it to still show 'angels, jesus, holy spirit' but to have the pink number next to each of those list items change to reflect how many keywords they each have that match one or more of the keywords you typed. So if i type 'holy spirit' then I want it to show the 'angels, jesus, holy spirit' list items, because they all have the keywords 'holy', so each list item's pink number should read 1, but 'angels' and 'holy spirit' also contain the hidden keyword 'spirit', so their pink numbers should increase by 1 each.

  • angels 2
  • jesus 1
  • holy spirit 2

now if I add 'archangel' to 'holy spirit' so i have 'holy spirit archangel' typed in, then the 'angels' list item's pink number should increase to 3, because it contains 3 of the keywords i've typed in, making it the most accurate one.

right now the pink numbers don't do anything, and it filters down and only shows the list items with the EXACT keywords. I need to correct these things, any help is MUCH appreciated. I've spent hours and hours on this.


If you always store the tags as lowercase, then just convert all typed entries to lowercase before you use the split. Additionally, you are presently matching against the text, not the tag list.

The way you have your matches test done, is like an & - AND, if you want it to be an | - OR then start false and switch to true when a positive match, rather than vice versa.

As for the counting, set all values to 0 at the commencement of a new scan, then when a tag is detected in the comparison loop, increment the value in that tag.

Updated Demonstration: http://jsfiddle.net/ape5U/22/


  1. var filter = $(this).val().toLowerCase()

Make the value of the filter lower case and ensure all tags are lower case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜