0

如果其他情况在这里不起作用,则播放框架

如果 userprofile.useraccountid、useraccount.id 具有相同的值,则不会在查看页面上查看该 id 用户

我在视图中的代码..

@(userprofiles: List[UserProfile],myFriend:models.MyFriend,userprofile:models.UserProfile,useraccount:models.UserAccount)
 @helper.form(action = routes.Application.createMyFriend) {
    <br/><br/><br/>
    @for(userprofile <- userprofiles){
        @if(userprofile.useraccountid != useraccount.id) {
            <img src="@routes.Assets.at("images/img2.png")" width="200" height="200" />
            <br>
            <h5>@userprofile.name</h5>
            <h5>@userprofile.useraccountid</h5>=<h5>@useraccount.id</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/>
        }
    } 
}  

检查条件时,数据库值是视图页面中的视图,并且

@if(userprofile.useraccountid != useraccount.id)

如果将条件更改为

 @if(userprofile.useraccountid == useraccount.id)

视图页面中不会出现任何内容。

在此代码中运行程序时的代码部分

 <h5>@userprofile.useraccountid</h5>=<h5>@useraccount.id</h5>

这里的 id 是相同的,并且在视图中显示那么这个想法不是错误的.. 例如 15 = 15。

这里的 2 id 是相同的,但是在 if 情况下的检查不能正常工作......或者编码不正确。

编辑这是在应用程序中

 def listMyFriend = Action { implicit request =>
    var cid=request.session.get("userId")
    println("aa",cid)
   if (request.session.get("userId") == 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)
       /*   val myfriendId = request.session.get("myFriendId").get.toLong//myFriendId
        val myfriend = MyFriend.friendidByUserIsAccepted(myfriendId,true)
        println(myfriend)*/
        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")
        })  
        }
    }  
4

1 回答 1

5

You have shadowing issues in your code: userprofile is both defined as a parameter of your template and as the variable you get out of the for comprehension.

@(userprofiles: List[UserProfile],myFriend:models.MyFriend,userprofile:models.UserProfile,useraccount:models.UserAccount)
                                                    here ---^
 @helper.form(action = routes.Application.createMyFriend) {
    <br/><br/><br/>
    @for(userprofile <- userprofiles){
and here ---^

Try renaming one of the two and sort out which one you want to refer to in your if.

于 2013-06-08T10:33:12.837 回答