현재 사용자의 선택을 추적 한 다음 해당 선택에 따라 페이지를 변경하는 것이 목적인 템플릿에 작업이 설정되어 있습니다.
이것은 내 router
:
this.resource('simpleSearch', function() {
this.resource('simpleSearchOption', {path: ':simpleSearchOption_id'});
조치는 다음과 같습니다.
<div {{action "select" this}} class="questiontile">
그리고 여기에 컨트롤러가 있습니다.
App.SimpleSearchOptionController = Ember.ObjectController.extend({
needs: ["simpleSearch"],
simpleSearch: Ember.computed.alias("controllers.simpleSearch"),
actions: {
select: function(optionId) {
var nextOptionId = parseInt(this.get("id")) + 1;
var numOfOptions = this.get('simpleSearch').get('model').length;
if(nextOptionId < numOfOptions) {
console.log('going to next option');
/** What do I do here?
* This is my current implementation,
* and it works, but is it proper?
*/
this.transitionToRoute('/simpleSearch/' + nextOptionId);
}
}
}
});
다음 페이지는 기본적으로 상위 경로 / 컨트롤러 / 뷰의 모델 인 객체 배열의 다음 인덱스입니다.
현재 내가하는 방법은 효과가 있지만 적절합니까? 'Ember 관용적'인가요?
이전 게시물에 대해 죄송합니다. 실수로 삭제했습니다! transitionToRoute는 두 개의 인수를 취합니다. 첫 번째는 자원 / 경로 이름이고 두 번째는 모델입니다. 그래서 이것은 작동합니다
actions: {
select: function(optionId) {
var nextOptionId = parseInt(this.get("id")) + 1;
this.store.find('simpleSearch', nextOptionId).then(function(model){
this.transitionToRoute('simpleSearchOption', model);
});
//OR MAYBE YOU COULD GET IT FROM THE PARENT CONTROLLER??
/*
MAYBE
this.get('simpleSearch.content').forEach(function(model){
if(model.get('id') === nextOptionId){ do transition}
else{ alert some msg!! }
})
*/
}
}
여기에 더 많은 정보 : http://emberjs.com/api/classes/Ember.Controller.html#method_transitionToRoute
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다