jeudi 26 mars 2015

How compare dinamic string in javascript

I need to compare two strings in a custom filter I created in angular . The problem is that the comparison is always false , and check the contents of both strings , length and type and are equal . I have dealt with localeCompare , "== " " === " but does not work. the strange thing is on the first part of if works fine and both parties did the same.


this is my code:



.filter('search',function(){
return function(items,arguments){//arguments -> object {columns,parameters}
var i=0,j=0,filtered=[],nmbStr="",comp="";
for(i=0;i<items.length;i++){
nmbStr = (items[i][arguments.columns[0]]).toString();
nmbStr = nmbStr.substr(0,arguments.parameters[0].length);
switch(arguments.parameters.length){
case 1:
if( nmbStr === arguments.parameters[0])
filtered.push(items.slice(i,i+1)[0]);
break;
case 2:
comp = (items[i][arguments.columns[1]]);
comp = comp.substr(0,arguments.parameters[1].length);
comp = comp.toLowerCase();
if( nmbStr === arguments.parameters[0] && comp === arguments.parameters[1]){
filtered.push(items.slice(i,i+1)[0]);//crea un nuevo objeto a partir del array no una referencia
}
break;
}
}
return filtered;
}
})


and I called like this:



$filter('search')(tempArray,{columns:['id','company_name'],parameters:['1052','in']});


please help me i don't not know what to do...


Aucun commentaire:

Enregistrer un commentaire