2

我有这个玉模板开始导致以下类型错误。

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)

我检查了三个“项目”数组中传递的内容,它们要么都是空的,要么包含带有_id字段的有效对象。数组没有空成员。

4

1 回答 1

2

在内联代码中,执行以下操作:

.row
  .span4
    h1 Open Items (#{openItems.length})
      +dolist(openItems)

而不是这个:

.row
  .span4
    h1 Open Items (#{openItems.length})
      mixin dolist(openItems)
于 2013-10-22T19:56:53.423 回答