1

我有如下 JSON 数组。


[
  {
    "_Id": "0001",
    "_PatentId": "0000",
    "_Text": "Employee",
    "_Value": "employee",
    "_PermissionLevel": 55      
  },
  {
    "_Id": "0002",
    "_PatentId": "0000",
    "_Text": "Employees",
    "_Value": "employees",
    "_PermissionLevel": 55
  },
 {
    "_Id": "0002",
    "_PatentId": "0001",
    "_Text": "Dept",
    "_Value": "Dept",
    "_PermissionLevel": 55
  }
]

使用这个 JSON 数组,我需要使用 like 运算符过滤员工。我在下面使用了查询,它工作正常。

var qryResult = Enumerable.From(_gramrTree).Where("$._Text == 'Employee'").OrderBy("$._Id").Select("$._Id").ToArray();

但我需要与类似的运营商合作..但它不起作用..

不成功的查询

var qryResult = Enumerable.From(_gramrTree).Where("$._Text like '%Emp%'").OrderBy("$._Id").Select("$._Id").ToArray();

var qryResult = Enumerable.From(_gramrTree).Where("$._Text % 'Emp'").OrderBy("$._Id").Select("$._Id").ToArray();
4

2 回答 2

2

请尝试此解决方法(似乎不包括在内)

.Where("~($._Text).toUpperCase().indexOf('emp'.toUpperCase())")

工作示例:

var _gramrTree = [{ "_Id": "0001", "_PatentId": "0000", "_Text": "Employee", "_Value": "employee", "_PermissionLevel": 55 }, { "_Id": "0002", "_PatentId": "0000", "_Text": "Employees", "_Value": "employees", "_PermissionLevel": 55 }, { "_Id": "0002", "_PatentId": "0001", "_Text": "Dept", "_Value": "Dept", "_PermissionLevel": 55 }],
    qryResult = Enumerable.From(_gramrTree).Where("~($._Text).toUpperCase().indexOf('emp'.toUpperCase())").ToArray();

document.write('<pre>' + JSON.stringify(qryResult, 0, 4) + '</pre>');
<script src="https://cdnjs.cloudflare.com/ajax/libs/linq.js/2.2.0.2/linq.js"></script>

于 2015-12-08T07:32:29.070 回答
0

我也找到了方法。。

var qryResult = Enumerable.From(_gramrTree)
    .Where("!!$._Text.match(/^"Emp"/i)")
    .OrderBy("$._Text")
    .Select("$._Text")
    .ToArray()
于 2015-12-08T09:17:01.987 回答