这是我的EmptyChildView:
define(['marionette', 'underscore',
'text!components/empty-options-view/template.html', 'config'],
function(Marionette, _, templateHTML, Config) {
'use strict';
var EmptyOptionsView = Marionette.ItemView.extend({
template: _.template(templateHTML),
className: 'empty-options',
initialize: function(options) {
this.link = options.url;
},
templateHelpers: function() {
return {
externalLink: function() {
return Config.get('base_url') + this.link;
}
};
}
});
return EmptyOptionsView;
});
以下是我使用它的方式:
define(['marionette', 'groups-menu/groups/item-view', 'components/empty-options-view/view',
'eventer'],
function (Marionette, GroupItemView, EmptyOptionsView) {
'use strict';
var GroupsCollectionView = Marionette.CollectionView.extend({
childView: GroupItemView,
emptyView: EmptyOptionsView,
emptyViewOptions: {
url: '/settings'
},
/**
* Toggles the "all" radio button on, unchecks all individual signup
* checkboxes.
* @method GroupsCollectionView.markAll
*/
markAll: function () {
this.collection.uncheckAll();
}
});
return GroupsCollectionView;
});
EmptyView将成为多个视图的共享组件。出于某种原因,我无法访问this.link
中的templateHelpers
(它返回undefined)
答案 0 :(得分:1)
templateHelpers
)调用 this
个函数。您需要将link
添加到序列化视图数据:
var EmptyOptionsView = Marionette.ItemView.extend({
// ...
serializeData: function() {
return _.extend(this.model.toJSON(), {
link: this.link;
}
},
templateHelpers: function() {
return {
externalLink: function() {
return Config.get('base_url') + this.link;
}
}
}
// ...
}