简体   繁体   English

未调用Route上的Ember.js RC1'模型'钩子

[英]Ember.js RC1 'model' hook on Route not called

It appears the model hook is not working as documented for RC1. 看来model挂钩无法按RC1的说明工作。 The model hook is not being called when a linkTo is used instead of visiting the item directly by editing the url in the browser. 当使用linkTo而不是通过在浏览器中编辑url直接访问项目时,不会调用model挂钩。

Given this example app: http://jsfiddle.net/wmarbut/QqDjY/ 给定此示例应用程序: http : //jsfiddle.net/wmarbut/QqDjY/

When visited directly at '/#/edit-item/3', the model hook is called, however when a linkTo call is used to direct the user to the same page, the model hook is not called. 当直接在'/#/ edit-item / 3'处访问时,将调用model挂钩,但是当使用linkTo调用将用户定向到同一页面时,不会调用model挂钩。

Given the documentation here http://emberjs.com/guides/routing/specifying-a-routes-model/ , I can't find anything to explain this. 给定http://emberjs.com/guides/routing/specifying-a-routes-model/中的文档,我找不到任何可以解释的信息。 Is this a bug or am I doing it wrong? 这是错误还是我做错了?

Edit I'm not using Ember Data nor do I plan to. 编辑我不使用Ember Data,也不打算使用。

It appears the model hook is not working as documented for RC1. 看来模型挂钩无法按RC1的说明工作。 The model hook is not being called when a linkTo is used instead of visiting the item directly by editing the url in the browser. 当使用linkTo而不是通过在浏览器中编辑url直接访问项目时,不会调用模型挂钩。

This is the exact way it's supposed to work. 这是它应该工作的确切方式。 This is because the model is given via linkTo . 这是因为该模型是通过linkTo给出的。 When you write {{linkTo posts post}} the model is the 3rd argument. 当您编写{{linkTo posts post}} ,模型是第三个参数。 There is no need to call the model hook. 无需调用模型挂钩。 The model hook is only executed when entering a state via the URL because it must look up a model. 仅当通过URL进入状态时才执行模型挂钩,因为它必须查找模型。

In your fiddle you have {{#linkTo editItem item.id}}{{item.name}}{{/linkTo}} . 在您的提琴中,您有{{#linkTo editItem item.id}}{{item.name}}{{/linkTo}} You do no need to do that. 您无需这样做。 You should have {{#linkTo editItem item}}{{item.name}}{{/linkTo}} . 您应该拥有{{#linkTo editItem item}}{{item.name}}{{/linkTo}} This will not solve the "problem" however. 但是,这不会解决“问题”。 It will make the lookup automatic. 它将使查找自动进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM