正确的方法使用coffeescript与ember的mixins

正确的方法使用coffeescript与ember的mixins

本文介绍了什么是正确的方法使用coffeescript与ember的mixins?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对我的英语表示歉意,



我试图用mixin扩展视图。代码是coffeescript:



View - 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()
如果@modalView
@ modalView.append()

当我尝试加载应用程序时,应用程序会引发此错误:

  Assertion failed:预期的哈希或Mixin实例,得到[object未定义] 

$ b / p>

解决:

  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()


b $ b App.FilmsFilmView = Em.View.extend App.ModalViewMixin,

templateName:films / show

看起来像应用加载FilmsFilmView时,mixin仍然未被初始化,并导致错误。

解决方案

这是因为当执行时:

  App.FilmsFilmView = Em.View.extend(App.ModalViewMixin ,... 

App.ModalViewMixin



确保 App.ModalViewMixin 之前出现<$ p c $ c> App.FilmsFilmView 。


Apologies for my english,

I am trying to extend a View with a mixin. The code is coffeescript :

View - 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()

when i try to load the app, the app throws this error:

Assertion failed: Expected hash or Mixin instance, got [object Undefined]

so, what is the correct way to write this ?

Thanks in advance

Update:

Solved with :

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"

Looks like when the app loads "FilmsFilmView", the mixin still is not initialized and it causes the error.

解决方案

This happen because when running:

App.FilmsFilmView = Em.View.extend(App.ModalViewMixin, ...

App.ModalViewMixin is undefined, it have to be defined before of it usage.

Ensure that App.ModalViewMixin appears before than App.FilmsFilmView.

这篇关于什么是正确的方法使用coffeescript与ember的mixins?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 19:16