2014-01-08 2 views
0

CRUD 기능이있는 users 모델이있는 엠버 응용 프로그램이 있습니다. CreateEdit 템플릿은 모두 트위터 부트 스트랩 모달로 렌더링됩니다. 내 문제는, 모달에서 Cancel 또는 Save Changes을 클릭하면 앱이 users 템플릿으로 돌아 가기를 원합니다. 대신 이러한 단추 중 하나를 클릭하면 모달이 사라지지만 url은/users/create 또는/users/edit에 남아 있습니다. 나는 아래와 같이 라우팅을 변경하려고 시도했지만 아무런 효과가 없다. 내 모달은 여러 가지 예를 통해 많은 인터넷 검색 및 코드를 조합 한 결과이므로 액션이 userEditView에 실제로 수행되는지 여부는 확실하지 않습니다. 누구든지 도와 줄 수 있습니까?닫을 때 잘못된 URL로 Ember 모달 라우팅

App.UserEditView = Ember.View.extend({ 
    templateName: "user/edit", 
    title: "", 
    content: "", 
    classNames: ["modal", "fade"], 
    didInsertElement: function() { 
     this.$().modal("show"); 
     this.$().one("hidden", this._viewDidHide); 
    }, 
    // modal dismissed by example clicked in X, make sure the modal view is destroyed 
    _viewDidHide: function() { 
     if (!this.isDestroyed) { 
      this.destroy(); 
     } 
    }, 
    // here we click in close button so _viewDidHide is called 
    close: function() {   
     this.$(".close").click(); 

//This is where I've tried to change the routing 

this.transitionToRoute('users'); 

    } 
}); 

내 템플릿 :

<script type = "text/x-handlebars" id = "user/edit"> 

<div class="modal-dialog"> 
    <div class="modal-content"> 
     <div class="modal-header"> 
     <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> 
     <h4 class="modal-title">Edit User</h4> 
     </div> 
     <div class="modal-body"> 
<div class = "input-group"> 
    <h5>First Name</h5> 
    {{input value=firstName}} 

    <h5>Last Name</h5> 
    {{input value=lastName}} 

    <h5>Email</h5> 
    {{input value=email}} 


     </div> 
     </div> 
     <div class="modal-footer"> 

     <a {{action close target="view"}} href="#" class="btn btn-default">Cancel</a> 
     <a {{action "save"}} class="btn btn-primary">Save changes</a> 

     </div> 
    </div><!-- /.modal-content --> 
    </div><!-- /.modal-dialog --> 

</script> 

내 컨트롤러 :

App.UsersCreateController = Ember.ObjectController.extend({ 


     actions: { 
     save: function(){ 
      console.log("this.get('model')", this.get('model')); 

      // create a record and save it to the store 
      var newUser = this.store.createRecord('user', this.get('model')); 
      console.log("newUser", newUser); 
      newUser.save(); 

      // redirects to the user itself 
      this.transitionToRoute('user', newUser); 
     } 
     } 
    }); 

그리고 내 경로 :

경로로 전환을 호출하여 타다 남은 routes에서 호출 할 수
App.UsersCreateRoute = Ember.Route.extend({ 
    model: function(){ 
    // the model for this route is a new empty Ember.Object 
    return Em.Object.create({}); 
    }, 

    renderTemplate: function(){ 
    this.render('user.create', { 
     controller: 'usersCreate' 
    }); 
    } 
}); 

답변

1

transitionTo("the_route")controllerstransitionToRoute("the_route")으로 전화하십시오. 표시기 view에서 전환해야하는 경우보기 this.controller.transitionToRoute("users");을 호출하십시오.

다음 예제에서는 부트 스트랩 모달 페이드 인/아웃을 실험하기 위해 create user에서 몇 가지 조정을했지만 일반적으로 내가 생각하는 것을 보여주기 위해 코드 스타일을 따랐습니다.

http://emberjs.jsbin.com/ASAPASU/1#/users

+0

대단한 jsbin! 취소를 클릭하면 완벽하게 작동하지만 새 레코드를 저장하면 모달이 닫히지 만 페이지가 사라지고 URL은 여전히 ​​/ users/newuserid에 남아 있습니다. 어떤 제안? – bookthief

+0

@bookthief 기꺼이 도와 줬어! 확인을 마치면 '저장'을 선택하면 두 개의 경고 대화 상자가 표시되고 사용자에게 전환됩니다 (크롬 31.x, ff 25.0에서 테스트 됨). – melc

+0

흠 View의 경고가 트리거되지 않아 어딘가에서 실수를하고 있습니다! – bookthief

관련 문제