场景是这样的:我有一个在几个地方使用的collectionView 。 我将一些选项传递到视图中以更改某些显示方面(主要是措辞),因为到处都是完全相同的行为。
我真的想将此自定义扩展到emptyView ,但我找不到这样做的方法。 似乎没有对emptyView上的collectionView引用,除了定义它之外,我似乎也无法从collectionView访问emptyView 。
基本上,我希望能够做到这样的事情:
var noItemsView = Backbone.Marionette.ItemView.extend({ tagName: "li", className: "no-results", template: Handlebars.compile(noResultsTemplate), }), leftToggleListView = Backbone.Marionette.CollectionView.extend({ tagName: "ul", className: "left-toggle-view-list", emptyView: noItemsView, initialize: function() { this.emptyView.model.set("name": "some custom name"); } });然后让noItemsView能够在其模板中呈现{{ name }} 。
有没有办法实现这一点,没有修改木偶?
The scenario is this: I have a collectionView that gets used in a couple of places. I pass a few options into the view to change certain display aspects (verbiage mostly), since the behavior is exactly the same everywhere.
I'd really like to extend this customization to the emptyView, but I can't find a way to do so. There seems to be no reference to the collectionView on the emptyView, and neither can I seem to access the emptyView from the collectionView, outside of defining it.
Basically, I'd like to be able to do something like this:
var noItemsView = Backbone.Marionette.ItemView.extend({ tagName: "li", className: "no-results", template: Handlebars.compile(noResultsTemplate), }), leftToggleListView = Backbone.Marionette.CollectionView.extend({ tagName: "ul", className: "left-toggle-view-list", emptyView: noItemsView, initialize: function() { this.emptyView.model.set("name": "some custom name"); } });And then have the noItemsView be able to render {{ name }} within its template.
Is there any way to accomplish this, short of modifying Marionette?
最满意答案
实际上你可以这样访问emptyView:
this.children._views[_.keys(this.children._views)[0]];似乎在新版本中我们将有一个允许获取emptyView 。 https://github.com/marionettejs/backbone.marionette/pull/727
Actually you can access to the emptyView in this way:
this.children._views[_.keys(this.children._views)[0]];Seems like in the new version we will have a method that allows to get an emptyView. https://github.com/marionettejs/backbone.marionette/pull/727
更多推荐
发布评论