2
這裏是我的行爲:MarionetteJS和不理解行爲
define(['marionette'], function (Marionette){
'use strict';
var Filter = Marionette.Behavior.extend({
events: {
'keyup @ui.filter': 'onFilter'
},
defaults: {
field: "name"
},
onFilter: function() {
console.log(this.options.field);
console.log(this.view);
}
});
return Filter;
});
這裏是我如何使用它
define(['underscore', 'jquery', 'marionette', 'text!components/slide-out-menu/template.html', 'eventer',
'behaviors/behavior.filter'],
function (_, $, Marionette, templateHTML, eventer, Filter) {
'use strict';
var SlideOutMenuView = Marionette.LayoutView.extend({
tagName: 'section',
className: 'menu open',
template: _.template(templateHTML),
ui: {
next: '.next',
prev: '.prev',
cancel: '.cancel',
submit: '.submit',
title: 'header h1',
filter: 'header input',
toggleGroups: '.toggle-groups',
toggleSegments: '.toggle-segments'
},
events: {
'click @ui.cancel': 'menuClose',
'click @ui.submit': 'updateSelection',
'click @ui.next': 'onNextClick',
'click @ui.prev': 'onPrevClick',
'click @ui.toggleGroups, @ui.toggleSegments': 'onToggleClick'
},
behaviors: {
Filter: {
behaviorClass: Filter
}
},
但我需要的行爲,以超越爲ItemView
這樣的:
var GroupItemView = Marionette.ItemView.extend({
tagName: 'article',
template: _.template(templateHTML),
ui: {
input: 'input'
},
events: {
'click': 'onSelect'
},
behaviors: {
Filter: {
behaviorClass: Filter,
field: "group_name"
}
},
行爲從LayoutView
內部明顯觸發但I ca沒有得到它在ItemView
內部發火... @ui.filter
屬性是LayoutView的一部分,所以也許這是我的問題,但是如何超越到ItemView?