0

我正在尝试使用 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

4

2 回答 2

0

你不应该像这样访问视图

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

这个PR可以给你更多的见解。

您所做的与 Stefanpenner 在此提交中所做的相同。

这是Wycats的回复。

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

于 2013-10-25T05:22:32.387 回答
0

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

你可以试试 appendTo('body')

于 2013-10-25T05:08:30.243 回答