gpt4 book ai didi

Ember.js 操作错误 : "Nothing handled the event"

转载 作者:行者123 更新时间:2023-12-02 06:05:29 24 4
gpt4 key购买 nike

我正在开发我的第一个 Ember.js 应用程序,虽然我有一个模板加载,但当我尝试调用我在 Controller 中定义的操作时,我收到一个错误:“ Uncaught Error :没有处理事件'showNew'。”我不确定我是否错误地设置了路线和 Controller ,或者我是否遗漏了其他东西。

./router.js:

Seanchai.Router.map(function(){
this.resource("stories", function(){
this.route('new');
});
});

Seanchai.StoriesRoute = Ember.Route.extend({
model: function(){
Seanchai.Story.find();
}
});


Seanchai.Router.reopen({
location: 'history'
});

./controllers/stories_controller.js:
Seanchai.StoriesController = Ember.ArrayController.extend({    

showNew: function() {
this.set('isNewVisible', true);
}
});

./templates/stories/index.hbs:
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
</thead>
<tbody>
{{#each stories}}
{{view Seanchai.ShowStoryView storyBinding="this"}}
{{/each}}
{{#if isNewVisible}}
<tr>
<td>*</td>
<td>
Test
</td>
</tr>
{{/if}}
</tbody>
</table>
<div class="commands">
<a href="#" {{action showNew}}>New Story</a>
</div>

如果我将操作移动到路由器中,就像这样,它可以工作,但根据文档,我应该能够在 Controller 中执行此操作。

更新了./router.js:
Seanchai.Router.map(function(){
this.resource("stories", function(){
this.route('new');
});
});

Seanchai.StoriesRoute = Ember.Route.extend({
model: function(){
Seanchai.Story.find();
},
events: {
showNew: function() {
this.set('isNewVisible', true);
}
}
});


Seanchai.Router.reopen({
location: 'history'
});

我显然错过了一些东西,但我不确定是什么。

最佳答案

我猜你的showNew事件未在 Controller 上触发,因为您有 stories.index模板,所以你应该 Hook 到对应的 Controller ,它应该是 StoriesIndexController :

Seanchai.StoriesIndexController = Ember.ArrayController.extend({    
showNew: function() {
this.set('isNewVisible', true);
}
});

希望能帮助到你

关于Ember.js 操作错误 : "Nothing handled the event",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16550592/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com