【问题标题】:Custom search function not working on android 5.1 and lower自定义搜索功能不适用于 android 5.1 及更低版本
【发布时间】:2016-09-28 12:09:28
【问题描述】:

我正在开发一个具有内置搜索功能的应用程序。但是,当我在模拟器中(以及在运行 Android 5.1 的 Nexus 7 (2012) 平板电脑上)在 Android 5.1 或更低版本上执行搜索时,我收到一条错误消息,指出“未定义不是函数”,这是迭代的第一行通过它必须搜索的列表。为什么这不适用于所有 Android 版本?

这是我的代码:

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

        }
    }

谁能告诉我在 5.1 或更低版本的 Android 设备上使用它有什么问题?提前致谢!

【问题讨论】:

    标签: javascript android ionic-framework emulation


    【解决方案1】:

    好的,所以问题是我使用了 .includes()。不知何故,此功能不适用于 Android 5.1 及更低版本。

    现在我使用了 .indexOf() !== -1,这不会产生任何问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-15
      • 1970-01-01
      相关资源
      最近更新 更多