我有以下数组:
var jobs = [
{ ID: 'grt34hggf', Title: 'tobi', Location: 'Los Angeles, CA', Description: "bla-bla-bla", DateExpiration: "FFF" },
{ ID: 'vbnhty', Title: 'n', Location: 'Los Angeles, CA', Description: "bla-bla-bla", DateExpiration: "FFF" },
{ ID: 'bnm7ii78', Title: 'bnui', Location: 'Los Angeles, CA', Description: "bla-bla-bla", DateExpiration: "FFF" }
];
然后我尝试从这个数组中获取一个元素。以下代码不起作用:
app.get('/job/:id', function (req, res) {
res.render('job', {
job: jobs.filter(function(x) { return x.ID == 'bnm7ii78'; }),
title: "Job Descr",
header: "descr"
});
});
但以下代码有效:
app.get('/job/:id', function (req, res) {
res.render('job', {
job : jobs[0],
title: "Job Descr",
header: "descr"
});
});
为什么?