0
私はユーザープロファイルページを表示するためのコントローラを作成しています。このページでは、ユーザープロジェクトとそのユーザーのフォローを見ることができます。私がJadeでビューをレンダリングすると、ボタンが何度も表示されます。私はこれがループの起こると思いますProject.find()
ビューレンダリング時に要素が何度も繰り返される
これは私がコントローラに持っているものです。
userShow : function(req, res){
Account.findOne({ username: req.params.username }, function(err, userWatch){
Follow.findOne({followingUserID : userWatch.id}, function(err, follows){
Project.find({ProjectOwner : userWatch.id}, function(err, projects){
res.render('account/profile',{
title : userWatch.username,
user : req.user,
watchUser : userWatch,
listProjects : projects,
listFollows : follows
});
});
});
});
},
そしてビューからのコンテンツ。 にconsole.logから
extends ../includes/layout
block content
div(class="wrap")
include ../includes/header
div(class="ink-grid")
div(class="column-group vertical-space")
div(class="all-100")
- console.log("console.log en vistas y listFollows: "+ listFollows);
- console.log("console.log en vistas y listProjects"+ listProjects);
h1 #{title}
if(user)
for follow in listFollows
form(method="post" action="/follows/#{watchUser.id}")
button(type="submit" class="ink-button green") follow
div(class="all-100")
div(class="all-50")
h3 #{watchUser.username}
p #{watchUser.emailAccount}
div(class="all-50")
button(class="ink-button grey") send message
div(class="all-100")
div(class="all-100")
div(class="all-80")
for project in listProjects
div(class="all-25")
figure(class="ink-image bottom-space")
figcaption(class="over-top dark")
p #{project.ProjectName}
img(src="/userFiles/projectImage/#{project.ProjectFileName}")
div(class="push")
include ../includes/footer
コンテンツ。
console.log en vistas y listFollows:
{ __v: 0,
alreadyFav: true,
followingUserID: '5720977ffe0697f51001c9a1',
fromFollowUserId: '5720977ffe0697f51001c9a1',
createdAt: Sat May 21 2016 19:23:43 GMT+0300 (+03),
updatedAt: Sat May 21 2016 19:23:43 GMT+0300 (+03),
_id: 57408b8fdecb09cb1a2a8b11 }
console.log en vistas y listProjects{ __v: 0,
ProjectLocation: 'Barcelona',
ProjectAmount: 5555555,
ProjectFileName: 'UploadedOn1462972254926fileOrigName13173780_1079858715421616_6060943026998765865_n.jpg',
ProjectDetails: 'Proyecto de prueba, usuario testauth5',
ProjectName: 'Proyecto 1',
ProjectOwner: '5720977ffe0697f51001c9a1',
_id: 57332f5fb4b04c3417fd32d7 },{ __v: 0,
ProjectLocation: 'Lugar fántastico',
ProjectAmount: 777777,
ProjectFileName: 'UploadedOn1462977655765fileOrigNamerapunzel__s_tower_2_by_rosequartz-d3f7i0u.jpg',
ProjectDetails: 'Loft acojedor con interior de madera. Perfecto para la clausura o encerrar a alguien.',
ProjectName: 'Torre de Rapunzel',
ProjectOwner: '5720977ffe0697f51001c9a1',
_id: 57334477b4b04c3417fd32d8 },{ __v: 0,
ProjectLocation: 'Lugar fantástico',
ProjectAmount: 900000,
ProjectFileName: 'UploadedOn1462979462355fileOrigNametumblr_mi43enfyLB1qcbsgdo1_500.jpg',
ProjectDetails: 'económico castillito de piedra y tejado de pizarra ',
ProjectName: 'Castillo de teja negra',
ProjectOwner: '5720977ffe0697f51001c9a1',
_id: 57334b86b4b04c3417fd32d9 },{ __v: 0,
ProjectLocation: 'Suiza',
ProjectAmount: 666666,
ProjectFileName: 'UploadedOn1463581840556fileOrigName13122913_798137460320744_2366020950260825105_o.jpg',
ProjectDetails: 'texto de prueba en proyecto 20',
ProjectName: 'proyecto 20',
ProjectOwner: '5720977ffe0697f51001c9a1',
createdAt: Wed May 18 2016 17:30:40 GMT+0300 (+03),
updatedAt: Wed May 18 2016 17:30:40 GMT+0300 (+03),
_id: 573c7c903f4b91120feecf93 },{ __v: 0,
ProjectLocation: 'Viena',
ProjectAmount: 2222222,
ProjectFileName: 'UploadedOn1463751212107fileOrigName8e03d5919704bfa20f45a94e207d5025.600x.jpg',
ProjectDetails: 'otro castillito de ejemplo',
ProjectName: 'little castle',
ProjectOwner: '5720977ffe0697f51001c9a1',
createdAt: Fri May 20 2016 16:33:32 GMT+0300 (+03),
updatedAt: Fri May 20 2016 16:33:32 GMT+0300 (+03),
_id: 573f122c7e0c94e760a6771b },{ __v: 0,
ProjectLocation: 'Suiza',
ProjectAmount: 888888,
ProjectFileName: 'UploadedOn1463752504948fileOrigName13217170_1078714605505775_6819378884998619975_o.jpg',
ProjectDetails: 'castillo en lo alto de las cumbres',
ProjectName: 'castillo de hielo',
ProjectOwner: '5720977ffe0697f51001c9a1',
createdAt: Fri May 20 2016 16:55:04 GMT+0300 (+03),
updatedAt: Fri May 20 2016 16:55:04 GMT+0300 (+03),
_id: 573f17387e0c94e760a6771c }
通常コンテンツと 回の正しい数として表示する番組でログ。
現在のユーザーが従うすべてのユーザーと、ボタンをレンダリングするユーザーのそれぞれについてループするループがあります。ボタンをループの外に置くことを意味しましたか? – nem035