通过子字符串过滤的结果错误

时间:2015-06-04 15:59:48

标签: javascript backbone.js

我正在创建一个过滤输入,根据keyUp提供结果。这就是我通过Backbone的集合进行过滤的过程:

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());
  

游乐场:http://jsfiddle.net/Lgcb0skm/

重点是:例如,当我输入h时,它只带来 Mitsubis h i C h < / em> evrolet ,而不是所有可能的结果,例如 H onda H yundai 等等为什么?建议?

2 个答案:

答案 0 :(得分:1)

尝试使用:

return model.get('name').toLowerCase().indexOf('h') > -1;

答案 1 :(得分:1)

简短回答myBigMatrix = 3 5 3 3 2 2 3 5 1 3 2 1 1 5 4 4 3 4 。如果要进行不区分大小写的匹配,则需要将文本字符串小写:

>> uniqueCol1.'
ans =
     1     3     4
>> uniqueCol2.'
ans =
     2     3     5

>> R
R = 
              []              []    [1x3 double]
    [2x3 double]              []    [2x3 double]
              []    [1x3 double]              []

>> R{2,1} %// submatrix corresponding to 3 in first col and 2 in second col
ans =
     3     2     2
     3     2     1

>> R{3,2} %// submatrix corresponding to 4 in first col and 3 in second col
ans =
     4     3     4