我创建了一个包含非常简单的列表(国家/地区)的示例,并根据此处的说明创建了api路由:https://gist.github.com/JedWatson/9741171
server.js:
app.get('/api/countries', keystone.middleware.api, routes.api.countries.list);
路线/ API/countries.js:
import keystone from 'keystone';
export function list(req, res) {
keystone.List('Country').model.find((err, items) => {
if (err) return res.apiError('database error', err);
res.apiResponse({
countries: items
});
});
}
Run Code Online (Sandbox Code Playgroud)
我收到错误Cannot read property 'find' of undefined,List对象存在但它没有model属性.有人知道为什么吗?keystone管理UI按预期工作,数据库中有多个对象.
| 归档时间: |
|
| 查看次数: |
372 次 |
| 最近记录: |