2016-08-05 5 views
0

편집 연필을 누르면 내 데이터베이스에서 가져온 테이블 행을 편집 할 수 없습니다. 양식에는 아무 것도 없지만 삭제를 위해 내가 원하는 모든 행에서 성공적으로 작동합니다. 여기 데이터베이스에서 검색된 데이터를 편집하고 양식의 텍스트 필드에 테이블의 데이터를 반환하는 방법

screenshot of my table row

내가 테이블 데이터를 얻을 history.scala.html 파일입니다

@(formList: List[Users],form: Form[Users]) 

@main("history") { 

    @for(i <- mtnUsers.all()) { 

     @if(i.client.equalsIgnoreCase("potato")) { 
     <table> 
      <tbody> 
       <tr> 
        <td> <a href="/#"><i>@i.firstname @i.lastname </i></a></td> 
        <td> <a href="/#"><i>@i.phonenumber</i></a></td> 
        <td> <a href="/#"><i>@i.amount</i></a></td> 
        <td> <a href="/#"><i>@i.doneAt</i></a></td> 
        <td> <a href="@routes.Application.edit(i.id)"><i><span class="glyphicon glyphicon-pencil"></span></i></a></td> 
        <td> <a href="@routes.Application.delete(i.id)"><i><span class="glyphicon glyphicon-trash"></span></i></a></td> 
       </tr> 
      </tbody> 
     </table> 
     } 
    } 
} 

내 컨트롤러 편집의 방법과

public static Result history(long id) { 
    Form<Users> taskData = form(Users.class); 
    return ok(history.render(Users.MTN(), taskData)); 
} 

public static Result edit(Long id) { 
    Form<Users> content = form(Users.class).fill(
    Users.find.byId(id)); 

    return ok(views.html.edit.render(id,content)); 
} 

public static Result update(Long id) { 
    Form<Users> updateForm = form(Users.class).bindFromRequest(); 
    if (updateForm.hasErrors()) { 
     return badRequest(edit.render(id, updateForm)); 
    } 
    updateForm.get().update(id); 

    return redirect(routes.Application.profile()); 
} 

그리고 edit.scala.html를 검색하는 일,해야 형태입니다 다음 데이터를 수정하려면

<form action="@routes.Application.update(id)" method="post"> 

    <div class="form-group row"> 
     <label class="col-sm-2 form-control-label">Phone Number</label> 
     <div class="col-sm-10"> 
     <input name="phonenumber" class="form-control" type="text" placeholder="Phone Number"> 
     </div> 
    </div> 

    <div class="form-group row"> 
     <label class="col-sm-2 form-control-label">First Name</label> 
     <div class="col-sm-10"> 
     <input name="firstname" id="firstname" minValue="2" class="form-control" type="text" placeholder="First Name"> 
     </div> 
    </div> 

    <div class="form-group row"> 
     <label class="col-sm-2 form-control-label">Last Name</label> 
     <div class="col-sm-10"> 
     <input name="lastname" id="lastname" class="form-control" type="text" placeholder="Last Name"> 
     </div> 
    </div> 

    <div class="form-group row"> 
     <label class="col-sm-2 form-control-label">User</label> 
     <div class="col-sm-10"> 
     <select class="form-control" name="client" id="client" value="client"> 
      <option value="select">select ..</option> 
      <option value="potato">potato</option> 
      <option value="kamagaju">kamagaju</option> 
     </select> 
     </div> 
    </div> 
    <div class="form-group row"> 
     <label class="col-sm-2 form-control-label">Amount</label> 
     <div class="col-sm-10"> 
     <input name="amount" id="" value="" class="form-control" type="number" placeholder="Rwfr"> 
     </div> 
    </div> 

    <div class="panel-footer"> 
     <input type="submit" class="btn btn-danger" value="Send"> 
     <input type="reset" class="btn btn-warning" value="Reset"> 
    </div> 
</form> 
+0

, 내가 편집을 의미하고 MySQL의 테이블의 행을 업데이트 "@ data.id_of_this_filed"

값. 내가 묵은 유일한 문제는 연필을 누른 후에 텍스트 편집에서 텍스트 값을 얻는 방법입니다. –

답변

0

내 edit.scala.html 템플릿에 굵게 표시된 다음 스크립트를 추가했다. 각 편집 텍스트 값에 내가 추가 : = 내가 모든 것을 아주 잘 작동 발견 무엇

@(data:Users,customerForm: Form[Users]) 

@main("edit") { 

    <form ... > 

..... 

<div class="form-group row "> 
           <label class="col-sm-2 form-control-label">Amount</label> 
           <div class="col-sm-10"> 
            <input 
              name="amount" 
              id="" 
              **value="@data.amount"** 
              class="form-control" 
              type="number" 
              placeholder="Rwfr"> 
           </div> 
          </div> 

....... 

    </form> 
     }