2011-04-23 105 views
0

我的JSON数据搜索字符与小写和大写

[ 
{"lastName":"Noyce","gender":"Male","patientID":19389,"firstName":"Scott","age":"53Y,"}, 
{"lastName":"noyce724","gender":"Male","patientID":24607,"firstName":"rita","age":"0Y,"} 
] 

var searchBarInput = TextInput.value; 
var results = []; // initialize array of results 
for (var i = 0; i < recentPatientsList.length; ++i) { 
    if (recentPatientsList[i].lastName.indexOf(searchBarInput) == 0) { 
    results.push(recentPatientsList[i].lastName); 
    } 
} 
alert('Results: ' + results.toString()); 

我得到的结果,但我想它的两个匹配大写和小写当我搜索其开始在字的字符。

回答

2

您可以在这两个字符串使用toUpperCase

if (recentPatientsList[i].lastName.toUpperCase().indexOf(searchBarInput.toUpperCase()) == 0) { 
1
if(recentPatientsList[i].lastName.toLowerCase().indexOf(searchBarInput.toLowerCase()) == 0) 
+0

AAAAH的替代'toUpperCase' = P – 2011-04-23 22:44:35