Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 字符串与自身比较时无法返回true。_Javascript_Html - Fatal编程技术网

Javascript 字符串与自身比较时无法返回true。

Javascript 字符串与自身比较时无法返回true。,javascript,html,Javascript,Html,我有一个用于排序和筛选的web应用程序。在我的一段代码中,我有一个函数: var filterOptions = { valueNames: ['department'] }; var employeeFilterList = new List('employees', filterOptions); $('#filter-engineering').click(function() { employeeFilterList.filter(function(item) { con

我有一个用于排序和筛选的web应用程序。在我的一段代码中,我有一个函数:

var filterOptions = { valueNames: ['department'] };

var employeeFilterList = new List('employees', filterOptions);

$('#filter-engineering').click(function() {
  employeeFilterList.filter(function(item) {
    console.log(item.values());
    if (item.values().department === "Engineering") {
      return true;
    } else {
      return false;
    }
  });
  return false;
});
本质上,这是在web应用程序上使用list.js对员工目录的排序功能,只返回那些在工程中的员工。现在是真正的问题了,无论如何,除了这个问题,这个代码应该可以工作

函数中的
console.log
返回下面显示的每个项目的值:


如您所见,该对象的部门值是
“Engineering”
,其中包含一些奇怪的编码。通过运行我的代码并刷新页面,我看到
item.values().department==“Engineering”
由于间距问题总是错误的。什么可能导致这样的事情?我该如何避免?有没有办法让我把多余的空间吃下去

使用
trim()
来删除不必要的空白,而不是
if(item.values().department==“Engineering”){
使用
if(item.values().department.trim()==“Engineering”){

是否尝试使用trim?情况如下:

var filterOptions = { valueNames: ['department'] };

var employeeFilterList = new List('employees', filterOptions);

$('#filter-engineering').click(function() {
  employeeFilterList.filter(function(item) {
    console.log(item.values());
    var sanitized = $.trim(item.values().department)
    if (sanitized === "Engineering") {
      return true;
    } else {
      return false;
    }
  });
  return false;
});