0
我送通過我的控制器的視圖,sails.js已經佈局參數,即標題和用戶:迭代JavaScript對象在玉
module.exports = {
index: function(req, res) {
User.find().done(function(err, users) {
res.view('home/index', {
title: 'Tester',
users: JSON.parse(JSON.stringify(users))
});
});
}
};
這個代碼是找到所有用戶(僅1截至目前的),我發送視圖與用戶作爲JSON。我試圖遍歷JSON並打印每個用戶的電子郵件,名稱和ID。
extends ../layout
block body
ul
each user in users
li= user.email
這是返回的數據:
[ { email: '[email protected]',
name: 'MyNameFull',
id: 1,
createdAt: '2014-05-17T03:41:16.000Z',
updatedAt: '2014-05-17T03:41:16.000Z' } ]
而且我得到第5行(each user in users
)此錯誤:
3| block body\n 4| \tul\n > 5| \t\teach user in users\n 6| \t\t\tli= user.email\n\nCannot read property 'length' of undefined"