播放框架if else case不工作

时间:2013-06-08 06:53:10

标签: scala playframework

播放框架,如果其他情况不起作用

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

1 个答案:

答案 0 :(得分:5)

您的代码中存在阴影问题:userprofile既被定义为模板的参数,也被定义为for理解中的变量。

@(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 ---^

尝试重命名其中一个,并在if中找出您要引用的那个。

相关问题