현재 Marionette 2.4.1을 사용 중입니다.마리오 네트 뷰의 적절한 뷰 수명주기는 무엇입니까?
하위 레이아웃보기 (B)가 표시 될 영역이 포함 된 상위 레이아웃보기 (A)가 있습니다. view (B)가 표시 될 때 올바르게 호출되는 view (B)에 onShow
메서드가 있습니다. 그러나 뷰 (B)가 숨겨져있을 때 호출 할 것으로 예상하려면 onEmpty
및 onBeforeEmpty
이 있습니다. 뷰 (B)가 채워지지만 빈 호출에서 {preventDestroy: true}
을 전달하는 영역을 비우는 함수가있는 뷰 (A)에서 호출됩니다.
내 문제는 내가 /이 #empty
이 그 트리거를 선택하지 않는보기 (A) 그러나,보기 (B)에서 호출 될 때 호출되는 before:empty
또는 empty
트리거에 데리러보기 (B)를 기대하고 있었다이다 . 심지어보기 (B)조차도 그 방아쇠를 당기는 것 같습니다.
여기서 예상되는 상황은 무엇입니까? 마리오네트의 소스 코드를 실행할 때, 나는 onBeforeEmpty
트리거가 내 소스 코드에 따라 호출되는 볼 수 있습니다
Marionette._triggerMethod = (function() {
// split the event name on the ":"
var splitter = /(^|:)(\w)/gi;
// take the event section ("section1:section2:section3")
// and turn it in to uppercase name
function getEventName(match, prefix, eventName) {
return eventName.toUpperCase();
}
return function(context, event, args) {
var noEventArg = arguments.length < 3;
if (noEventArg) {
args = event;
event = args[0];
}
// get the method name from the event name
var methodName = 'on' + event.replace(splitter, getEventName);
var method = context[methodName];
var result;
// call the onMethodName if it exists
if (_.isFunction(method)) {
// pass all args, except the event name
result = method.apply(context, noEventArg ? _.rest(args) : args);
}
// trigger the event, if a trigger method exists
if (_.isFunction(context.trigger)) {
if (noEventArg + args.length > 1) {
context.trigger.apply(context, noEventArg ? args : [event].concat(_.drop(args, 0)));
} else {
context.trigger(event);
}
}
return result;
};
})();
가 나는 그것이 방법 onBeforeEmpty
을 트리거 의심 여기서
// get the method name from the event name
var methodName = 'on' + event.replace(splitter, getEventName);
var method = context[methodName];
는 것 같다 문맥 같이 전망 (A)이다. 빈
Mariontte의 지역 번호 :
이// Destroy the current view, if there is one. If there is no
// current view, it does nothing and returns immediately.
empty: function(options) {
var view = this.currentView;
var preventDestroy = Marionette._getValue(options, 'preventDestroy', this);
// If there is no view in the region
// we should not remove anything
if (!view) { return; }
view.off('destroy', this.empty, this);
this.triggerMethod('before:empty', view);
if (!preventDestroy) {
this._destroyView();
}
this.triggerMethod('empty', view);
// Remove region pointer to the currentView
delete this.currentView;
if (preventDestroy) {
this.$el.contents().detach();
}
return this;
},
그래서 여기 this.triggerMethod('before:empty', view);
이 this
것 같아보기을 의미한다 (A)와 view
는 (B) 볼을 말한다. 이것은 의도 된 것입니까? 나는 그 방법이 (B)보기에서 방아쇠를 당길 것이라고 생각 했는가? 그러나보기 (A) 중 하나에서 트리거되는 메서드를 볼 수 없습니다.