2013-06-17 5 views
1

에서 나는 내 응용 프로그램에서 개체 (노드)을 편집 할 수있는 다음과 같은 두 가지 경로가 있습니다액세스 검색 기록 타다 남은

  1. 목록 노드 -> 편집 아이콘을 클릭
  2. 목록 노드 -> 선택 노드 - > 편집 버튼을 클릭하십시오.

편집을 취소 할 수있는 옵션이 있습니다. 취소 할 때 라우터 (컨트롤러)를 올바른 위치로 되돌리려합니다. 즉, 노드 목록에서 나온 경우 취소를 "노드 목록"(#nodes)으로 되돌리려합니다. 노드보기에서 왔으면 취소를 노드보기 (#nodes/show/node-id)로 되돌리려 고합니다. 당신이 볼 수 있듯이

SettingsApp.NodesEditController = Ember.ObjectController.extend({ 
    needs: ['nodesIndex'], 
    selectedNode: null, 
    selectedNodeType: null, 
    nodes: [], 
    ... 
    cancel: function() { 
     this.stopEditing(); 
     this.transitionToRoute('nodes.show', this.get('content')); 
    }, 

    ... 
}); 

cancel 조치에 대한 경로를 고정 (nodes.show) : 현재이 내 NodesEditController의 구현입니다. 그러나 첫 번째 경우에 나는 this.transitionToRoute('nodes.index');을하고 싶습니다.

cancel: function() { 
    this.stopEditing(); 
    if (some_test) { this.transitionToRoute('nodes.show', this.get('content')); 
    } else { this.transitionToRoute('nodes.index'); } 
} 

어떻게 some_test을 구현하기 : 그래서 내 cancel 방법은 다음과 같이해야합니다? 현재 경로에 어떻게 도달했는지 알기 위해 무엇을 테스트 할 수 있습니까? 경로가 종료 될 때

답변

1

currentPath를 저장하는 Ember.Route 다시 열기 :

Ember.Route.reopen({ 
    deactivate: function() { 
    var applicationController = this.controllerFor('application'); 
    App.previousPath = applicationController.get('currentPath'); 
    } 
}); 

를 그런 다음 취소 방법 :

goBack: function() { 
    if (SettingsApp.previousPath == 'nodes.show') { 
     this.transitionToRoute(SettingsApp.previousPath, this.get('content')); 
    } else { 
     this.transitionToRoute(SettingsApp.previousPath); 
    } 
}, 

cancel: function() { 
    this.stopEditing(); 
    this.goBack(); 
}, 

참고 :이 경우 일부 대체를 제공 할 수 있습니다 응용 프로그램입니다 nodes.edit 경로에로드 됨.

+0

'Ember.Route.reopen'이 될까요? 내 앱에서 어디서든 할 수 있습니까? 죄송합니다. 초보자는 여기 있습니다. – dangonfast

+0

감사합니다. 정말로'Ember.Route.reopen'이었습니다. 좀 더 완성되도록 회신을 약간 수정했습니다. – dangonfast

관련 문제