等待 lodash 找到完成
wait for lodash find finish
我在 NodeJS 应用程序中使用 lodash。我想使用 _.find
。
但是我必须等待_.find
完成才能使用找到的信息,否则我要使用它时会undefined
。
var items = [
{ id: 001
// Super Object
// +150 properties each
},
{ id: 002 } // up to 200
];
var foundItem = _.find ( items , { id: 002 });
console.log(foundItem);
// => logs Undefined
我该怎么做?我需要等待 lodash _.find
完成才能打印找到的项目。
看到你把你的 id 写成 001
我猜它们是字符串而不是数字,所以也许引用你的值就可以了:
var foundItem = _.find ( items , { id: '002' });
我在 NodeJS 应用程序中使用 lodash。我想使用 _.find
。
但是我必须等待_.find
完成才能使用找到的信息,否则我要使用它时会undefined
。
var items = [
{ id: 001
// Super Object
// +150 properties each
},
{ id: 002 } // up to 200
];
var foundItem = _.find ( items , { id: 002 });
console.log(foundItem);
// => logs Undefined
我该怎么做?我需要等待 lodash _.find
完成才能打印找到的项目。
看到你把你的 id 写成 001
我猜它们是字符串而不是数字,所以也许引用你的值就可以了:
var foundItem = _.find ( items , { id: '002' });