本文介绍了使用Marionette.ItemView的看法,并没有模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它是常规使用 Marionette.ItemView 对于不具有模式财产有关的特定视图类他们?

Is it conventional to use Marionette.ItemView for view classes that do not have a specific model property associated with them?

由于 Marionette.View 并不意味着可以直接使用,这似乎是一个 ItemView控件有意义的,因为一个鉴于方便默认和绑定类。

As Marionette.View is not meant to be used directly, it seems like an ItemView makes sense as a view class with convenient defaults and bindings.

或者,你应该只是求助于使用 Backbone.View ?如果是这样,是有办法钩 Backbone.View 成木偶的事件触发和垃圾收集架构?

Or, should one just resort to using Backbone.View? If so, is there a way to hook Backbone.View into Marionette's evented and garbage-collected architecture?

感谢您的澄清!

推荐答案

ItemView控件可以不用模型中使用。我很经常这样做。

ItemView can be used without a model. I do this quite regularly.

如果你需要一个ItemView控件指定数据,但没有在Backbone.Model这些数据,你需要重写 serializeData 方法:

If you need to specify data for an ItemView, but not have that data in a Backbone.Model, you need to override the serializeData method:


MyView = Marionette.ItemView.extend({
  serializeData: function(){
    return {
      my: "custom data"
    };
  }
});

的基Marionette.View心不是'意味着被直接使用,因为它没有提供关于它自己的一个渲染功能。这并不意味着你不能用它来创建自己的基地视图类型,虽然。你可以,例如,建立您的应用程序与3D渲染谷歌地图或者第三方插件或其他东西有关系的视图类型,这并不需要一个ItemView控件中有一般Backbone.Model基于渲染。

the base Marionette.View isnt' meant to be used directly because it doesn't provide a render function on it's own. That doesn't mean you can't use it to create your own base view types, though. You could, for example, build a view type for your application that deals with rendering google maps or a third party widget or something else that doesn't need the general Backbone.Model based rendering that ItemView has in it.

这篇关于使用Marionette.ItemView的看法,并没有模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 22:01