Backbone Marionette:我可以为collectionView的emptyView提供选项吗?(Backbone Marionette: can I supply options to

系统教程 行业动态 更新时间:2024-06-14 17:01:34
Backbone Marionette:我可以为collectionView的emptyView提供选项吗?(Backbone Marionette: can I supply options to a collectionView's emptyView?)

场景是这样的:我有一个在几个地方使用的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

更多推荐

本文发布于:2023-04-20 18:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/33bb46f29d9c21e52d979b9fc4d40ec3.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我可   选项   Backbone   Marionette   collectionView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!