【发布时间】:2016-05-31 12:48:54
【问题描述】:
我的 JSON 看起来像这样
[{"id":"7","name":"hello","username":"hell7s692","password":"dAggzyFMnBXq3RjoTWoJ3ndBkGhyU6njT2ZPlNfXVV8+XU3vvrTaULUAbPcmsqgj1NpXOpzieKRXWox\/BVcYrA==","email":"hello@gmail.com","mobile_number":"7736527089","address":"hello","date":"24 Jan 2016 12:14:02","active":"1","commission":"5"},
{"id":"7","name":"hello","username":"hell7s692","password":"dAggzyFMnBXq3RjoTWoJ3ndBkGhyU6njT2ZPlNfXVV8+XU3vvrTaULUAbPcmsqgj1NpXOpzieKRXWox\/BVcYrA==","email":"hello@gmail.com","mobile_number":"7736527089","address":"hello","date":"24 Jan 2016 12:14:02","active":"1","commission":"5"}
]
从这里我想得到与类似查询中的条件匹配的新 json
即我想得到符合条件的json
获取名称以字母开头的所有json对象
类似mysql查询where name like he%
目前我只知道matches,但它返回的数组只有完全匹配。
var users = [
{ 'user': 'barney', 'age': 36, 'active': true },
{ 'user': 'fred', 'age': 40, 'active': false }
];
_.filter(users, _.matches({ 'age': 40, 'active': false }));
// → [{ 'user': 'fred', 'age': 40, 'active': false }]
这将只返回完全匹配。
【问题讨论】: