2016-09-28 36 views
0

我正在開發一款內置搜索功能的應用程序。但是,當我在模擬器(還有運行Android 5.1的Nexus 7(2012)平板電腦)上搜索Android 5.1或更低版本時,出現錯誤,說明「undefined不是函數」,它位於迭代的第一行通過它必須搜索的列表。 Whyis在所有Android版本上無法正常工作?自定義搜索功能不適用於Android 5.1及更低版本

這裏是我的代碼:

controllers.js

$scope.vacaturesZoeken = function() { 

    // Variable is value of search box 
    var zoekterm = document.getElementById('search_id').value; 

    // Check whether there is a proper search term in the variable 
    if (zoekterm.length === 0 || zoekterm.length === 1) { 

     // Variable is null, this will be used to check in the function 
     zoekterm = null; 

    } 

    // Search function 
    Vacatures.zoek($scope, zoekterm); 
} 

services.js

// Defining search function 
zoek: function($VacatureZoekLijstscope, zoekterm) { 

    // Setting variable for found items to 0 
    searched.length = 0; 

    // For every item in vacatures 
    for (var i = 0; i < vacatures.length; i++) { 

     // When the box is checked to only search for location 
     if (document.getElementById("locatie_check").checked === true) { 

     // Here is where is checked whether the variable is null 
     if (zoekterm === null) { 

      return false; 
     } 

     // When the searchterm is in the location property of an item 
     else if (vacatures[i].locatie.toLowerCase().includes(zoekterm.toLowerCase())) { 

      // Add item to variable 
      searched.push(vacatures[i]); 

     } 
    } 

誰能告訴我什麼是使用這個Android裝置上的5.1版本腳麻或更低?提前致謝!

回答

0

好吧,所以問題是我用.includes()。不知何故,這個功能在Android 5.1及更低版本上無法使用。

現在我使用.indexOf()!== -1,並沒有給出任何問題。

相關問題