这是我的视图页面,这里没有获取ID ..
@(userprofiles: List[UserProfile], myFriend: models.MyFriend, userprofile: models.UserProfile)
@helper.form(action = routes.Application.listMyFriend) {
值id不是List[models.UserProfile]
以下是发生错误的地方:
@for(userprofile <- userprofiles.id) {
@if(userprofile.id == userprofiles) {
} else {
<img src="@routes.Assets.at("images/img2.png")" width="200" height="200" />
<br><h5>@userprofile.name</h5>
<h6>@userprofile.gender</h6>
<h6>@userprofile.date_of_birth</h6>
<div class="actions">
<input type="submit" class="btn primary" value="+1 Add As Friend" title="Send Friend Request"></div>
<br/>
}
}
}
这是申请中的方法
def listMyFriend = Action { implicit request =>
if (request.session.get("myFriendId") == None) {
Results.Redirect("/")
} else {
val userprofiles: UserProfile = null
val userprofileId = request.session.get("userId").get.toLong // userProfileId
val userprofile = UserProfile.findUserByAccountId(userprofileId).get
println(userprofile)
myFriendForm.bindFromRequest.fold(
errors => BadRequest(views.html.myFriend(errors, userprofile, myfriend, myfrnd)),
myFriend => {
println("errors")
val myFriendOpt = UserProfile.myFriend(userprofile.id.get)
println(myFriendOpt)
myFriendOpt match {
case None =>
}
Results.Redirect("/myFriend")
}
)
}
}
这是路线:
POST /createMyFriend controllers.Application.listMyFriend
GET /allFriends controllers.Application.listAllFriends(userId:Long)
答案 0 :(得分:4)
错误消息告诉您出了什么问题。您的userprofiles
是UserProfile
的列表。它没有名为id
的成员。但是,您正试图访问它:
@for(userprofile <- userprofiles.id)
// ^--- this is invalid
我认为你要做的是:
@for(up <- userprofiles){
@if(up.id == userprofile.id) {} else { ... }
}