为我的英语道歉,
我正在尝试使用 mixin 扩展视图。代码是咖啡脚本:
查看 -films_film_view.js.coffee
App.FilmsFilmView = Em.View.extend App.ModalViewMixin,
templateName: 'films/show'
Mixin - modal_view_mixin.js.coffee
App.ModalViewMixin = Em.Mixin.create
modalView: null
click: ->
@showModalView()
close: ->
@closeModalView()
closeModalView: ->
if @modalView
@modalView.close()
showModalView: ->
@closeModalView()
@modalView = @createModalView()
if @modalView
@modalView.append()
当我尝试加载应用程序时,应用程序会抛出此错误:
Assertion failed: Expected hash or Mixin instance, got [object Undefined]
那么,写这个的正确方法是什么?
提前致谢
更新:
解决了:
App.ModalViewMixin = Em.Mixin.create
modalView: null
click: ->
@showModalView()
close: ->
@closeModalView()
closeModalView: ->
if @modalView
@modalView.close()
showModalView: ->
@closeModalView()
@set modalView, @createModalView()
if @modalView
@modalView.append()
App.FilmsFilmView = Em.View.extend App.ModalViewMixin,
templateName: "films/show"
看起来当应用程序加载“FilmsFilmView”时,mixin 仍未初始化并导致错误。