我有这个jade模板开始导致以下TypeError。
TypeError: /home/jared/code/fiestah-admin/views/items.jade:11
9| a(href=urlFor('item details', {
10| params: {
\> 11| //id: item._id
12| }
13| })) #{item.name}
14| .planner By
Cannot read property '_id' of null
at list_mixin (eval at <anonymous> (/home/jared/code/fiestah-admin/node_modules/jade/lib/jade.js:176:8))
at list_mixin (eval at <anonymous> (/home/jared/code/fiestah-admin/node_modules/jade/lib/jade.js:176:8))
at eval (eval at <anonymous> (/home/jared/code/fiestah-admin/node_modules/jade/lib/jade.js:176:8))
at Object.exports.compile (/home/jared/code/fiestah-admin/node_modules/jade/lib/jade.js:181:12)
at ServerResponse.res._render (/home/jared/code/fiestah-admin/node_modules/express/lib/view.js:425:21)
at ServerResponse.res.render (/home/jared/code/fiestah-admin/node_modules/express/lib/view.js:318:17)
at render (/home/jared/code/fiestah-admin/controllers/items-controller.js:23:7)
at module.exports (/home/jared/code/fiestah-admin/controllers/items-controller.js:41:5)
at Request._callback (/home/jared/code/fiestah-admin/node_modules/lib/libraries/api.js:95:5)
at Request.init.self.callback (/home/jared/code/fiestah-admin/node_modules/request/main.js:120:22)
它抱怨了一个属性_id
,但我认为它实际上并不属于 item._id
。如果我注释掉该行,或者在id之前添加另一个参数,则行号会更改,但异常保持不变。我甚至删除了模板中对_id
的两个引用,但异常是相同的。
以下是模板:
.page-header
h1 Items
mixin list(items)
hr
ul.index
- each item in items
li
a(href=urlFor('item details', {
params: {
id: item._id
}
})) #{item.name}
.planner By
|
a(href=urlFor('user details', {
params: {
id: item.planner._id
}
})) #{item.planner.name.full}
.row
.span4
h1 Open Items (#{openItems.length})
mixin list(openItems)
.row
.span4
h1 Open Items - No Offers (#{emptyItems.length})
mixin list(emptyItems)
.row
.span4
h1 Past Items (#{pastItems.length})
mixin list(pastItems)
我已经检查了三个“items”数组中传递的内容,它们都是空的或包含_id
个字段的有效对象。数组中没有空成员。
答案 0 :(得分:2)
在内联代码中,执行以下操作:
.row
.span4
h1 Open Items (#{openItems.length})
+dolist(openItems)
而不是:
.row
.span4
h1 Open Items (#{openItems.length})
mixin dolist(openItems)