【问题标题】:ItemView has no method 'render'ItemView 没有“渲染”方法
【发布时间】:2012-11-06 20:52:46
【问题描述】:

我刚刚将backbone.marionette 从0.9.3 更新到v1.0.0-beta4,下面的代码被破坏了:

PlansApp.CompositeView  = Backbone.Marionette.CompositeView
PlansApp.ItemView = Backbone.Marionette.ItemVie

PlansApp.Plans.PlansList = do ({PlansApp, Backbone} = window) ->
  PlansList = {}

  PlansListItemView = PlansApp.ItemView.extend
    initialize: ->
      @bindTo this.model, "change", this.modelChanged

    modelChanged: (model, value)->
      this.render()
      this.$el.effect("highlight", {}, 6000)
      window.addTeachMeHandlers() if model.get 'IsFirst

它专门破坏了 this.render() 并显示错误消息:

Uncaught TypeError: Object [object Object] has no method 'render'

此代码以前用于升级之前的工作。

从源码看,ItemView还有一个render方法,所以我猜测是上下文错误或者可能是bindTo发生了变化。

我也将下划线从 1.3 升级到 1.4.1

【问题讨论】:

    标签: marionette


    【解决方案1】:

    在以前的版本之一中,我不得不更改 EventBinder 与视图的连接方式,以避免与 Backbone.StickIt 插件发生冲突。此更改意味着事件绑定的默认上下文不再是视图,您必须在调用 bindTo 时指定第四个参数 - 上下文。它与 Backbone 的 on 方法相同:

    @bindTo this.model, "change", this.modelChanged, this

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-08
      • 1970-01-01
      • 2012-04-15
      • 1970-01-01
      • 2018-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多