2

I have this jade template that started causing the following 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)

It complains about a property _id, but I don't think it is actually pertaining to item._id. If I comment the line out, or add another parameter before id, the line number changes, but the exception remains the same. I've even removed both references to _id in the template, and the exception is the same.

Here is the template:

.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)

I've checked what is being passed in the three "items" arrays, and they are all either empty or contain valid objects with _id fields. There are no null members of the arrays.

robertklep
  • 198,204
  • 35
  • 394
  • 381
Jared
  • 2,043
  • 5
  • 33
  • 63

1 Answers1

2

Within the inline code, do this:

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

rather than this:

.row
  .span4
    h1 Open Items (#{openItems.length})
      mixin dolist(openItems)
Dan0
  • 536
  • 6
  • 5