Ember查看未找到控制器/操作

时间:2013-10-24 21:44:27

标签: ember.js

我试图从我对Ember的观点中调用我的控制器的动作,但它说:

Uncaught TypeError: Cannot call method 'send' of null

我找不到在ember中使用视图的正确方法。

我的视图布局有一个调用:

<button type="button" {{action modalConfirmation target="view"}} class="btn btn-primary">Save changes</button>

我的View类尝试以这种方式调用控制器:

this.get('controller').modalConfirmation();

我的控制器有这样的东西:

ProjEmber.BananasIndexController = Ember.ArrayController.extend({
  actions: {
    showModal: function() {
        modalinaView.title = "My Title";
        modalinaView.templateName = "any_template_you_wish";
        modalinaView.append();   
    },
    modalConfirmation: function() {
      console.debug('Action modalConfirmation');
    }
  }
});

OBS:如果我使用这样的帮助器附加我的视图,它会起作用:

{{#view ProjEmber.ModalinaView title='A title'}}
    A not so good application of a modal view. Just for the sake of illustration.
{{/view}}

您可以在Github上看到完整的源代码,特别是提交的这一部分: https://github.com/lucaspottersky/ember-lab/commit/4862426b39adc0bbcce0b4cc3fd0099439f8dd55#commitcomment-4421854

2 个答案:

答案 0 :(得分:0)

很有可能它没有被附加在正文中,或者你的余烬应用程序的范围,这就是事件没有传播到你的动作哈希的原因。

您可以尝试appendTo('body')

答案 1 :(得分:0)

您不应该访问此类视图

  

var modalinaView = this.container.lookup('view:modalina');

PR可以为您提供更多见解。

你和Stefanpenner在commit中所做的一样。

this是Wycats的回复。

或者,这个answer可以帮助您实例化模态