2011-04-23 96 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