0

Here is my view page and here not get the id..

@(userprofiles: List[UserProfile], myFriend: models.MyFriend, userprofile: models.UserProfile)
@helper.form(action = routes.Application.listMyFriend) {

Value id is not a member of List[models.UserProfile]

Here is where the error occurred:

    @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/>
        }
    }
}

This is method in application

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")
            }
        )
    }
}

And this is Routes:

POST /createMyFriend    controllers.Application.listMyFriend
GET  /allFriends        controllers.Application.listAllFriends(userId:Long)
4

1 回答 1

4

错误消息告诉您出了什么问题。你userprofiles是一个列表UserProfile。它没有名为 的成员id。但是,您正在尝试访问它:

@for(userprofile <- userprofiles.id)
//                              ^--- this is invalid

我认为你想要做的是:

@for(up <- userprofiles){
  @if(up.id == userprofile.id) {} else { ... }
}
于 2013-06-08T08:57:35.770 回答