Odczytanie atrybutu z nieistniejącego obiektu

0

Witam,

Uczę się JS. Zrobiłem przykładowy projekt z framework'iem Expres.js gdzie renderuję pliki JADE. Niestety błąd mam jak niżej:

Serwer Express nasłuchujący na porcie 4322
TypeError: /home/ff/t2_blog/views/index.jade:6
    4|   - var menu = 'index'
    5| block content
  > 6|   if (articles.length === 0)
    7|     | Brak opublikowanej treści.
    8|     a(href="/login") Zaloguj się
    9|     |  aby dodać artykuł.

Cannot read properties of undefined (reading 'length')
    at eval (eval at exports.compile (/home/damian/t2_blog/node_modules/jade/lib/jade.js:172:8), <anonymous>:221:16)
    at eval (eval at exports.compile (/home/damian/t2_blog/node_modules/jade/lib/jade.js:172:8), <anonymous>:360:22)
    at res (/home/damian/t2_blog/node_modules/jade/lib/jade.js:173:38)
    at Object.exports.render (/home/damian/t2_blog/node_modules/jade/lib/jade.js:269:10)
    at Object.exports.renderFile (/home/damian/t2_blog/node_modules/jade/lib/jade.js:305:18)
    at View.exports.renderFile [as engine] (/home/damian/t2_blog/node_modules/jade/lib/jade.js:290:21)
    at View.render (/home/damian/t2_blog/node_modules/express/lib/view.js:76:8)
    at Function.app.render (/home/damian/t2_blog/node_modules/express/lib/application.js:502:10)
    at ServerResponse.res.render (/home/damian/t2_blog/node_modules/express/lib/response.js:783:7)
    at Object.handle (/home/damian/t2_blog/app.js:13:7)

Mój plik app.js

var express = require('express');

var http = require('http');
var path = require('path');

var app = express();

app.set('port', process.env.PORT || 4322);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

app.all('*', function(req, res) {
  res.render('index', {msg: 'Witaj w Practical Node.js!'})
})


var server = http.createServer(app);
var boot = function () {
  server.listen(app.get('port'), function(){
    console.info('Serwer Express nasłuchujący na porcie ' + app.get('port'));
  });
}
var shutdown = function() {
  server.close();
}
if (require.main === module) {
  boot();
} else {
  console.info('Aplikacja uruchomiona jako moduł')
  exports.boot = boot;
  exports.shutdown = shutdown;
  exports.port = app.get('port');
}

index.jade

extends layout
 
block page
  - var menu = 'index'
block content
  if (articles.length === 0)
    | Brak opublikowanej treści.
    a(href="/login") Zaloguj się
    |  aby dodać artykuł.
  else
    each article, index in articles
      div
        h2
          a(href="/articles/#{article.slug}")= article.title

Co jest nie tak ?

0

articles jest null

0

Nie widzę abyś gdziekolwiek przekazywał tą tablice do templatki więc jak masz na niej operować?

1 użytkowników online, w tym zalogowanych: 0, gości: 1