javascript - Wrong result for filtering by substring -


i creating filtering input brings results according keyup. doing filtering, through backbone's collection:

var brand = backbone.model;  var brands = backbone.collection.extend({     model: brand,     filterbyname: function () {         return this.filter(function (model) {             return model.get('name').indexof('h') > -1;         });     } });  var fiat = new brand ({ name: 'fiat' }); var honda = new brand ({ name: 'honda' }); var chevrolet = new brand ({ name: 'chevrolet' }); var peugeot = new brand ({ name: 'peugeot' }); var mitsubishi = new brand ({ name: 'mitsubishi' }); var hyundai = new brand ({ name: 'hyundai' });  var brands = new brands ([ fiat, honda, chevrolet, peugeot, mitsubishi, hyundai ]);  console.log(brands.filterbyname()); 

playground: http://jsfiddle.net/lgcb0skm/

the point is: when type h, instance, brings me mitsubishi , chevrolet, instead of possible results, such honda, hyundai, etc. why? suggestions?

short answer 'h' != 'h'. need lower case text string if want case insensitive matches:

return this.filter(function (model) {     return model.get('name').tolowercase().indexof('h') > -1; }); 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -