究竟在哪里添加序列化挂钩(emberJS)
Where exactly to add serialize hook (emberJS)
我一直在关注 tutorialspoint.com 上的 EmberJS 教程,并且正在浏览“routes”部分,当我遇到 this page. It explains how to use dynamic segments in ember. So far I understand the code on how the route.js is updated and how the hbs file is created etc. (that's all pretty straightforward). What I don't understand is the last part where a serialize hook is made. I understand the code, but don't exactly know in which file should I put it? There is no mention of it in the tutorial, and I searched Whosebug as well but the only answer relevant to this was this 时解释它们是如何工作的而不是在哪里添加它们。有人可以解释一下我应该在哪个文件中添加这段代码吗?谢谢
查看 emberjs api。 serialize(model) 是 class 路由的一种方法。通常您不必实现该方法,因为在大多数情况下默认实现就足够了。默认实现将模型的 ID 添加为定义路由的动态段。
//router
Router.map(function() {
this.route('user', { path: '/user/:user_id' }); //user_id is the dynamic segment
});
//route with default serialize implementation
import Route from '@ember/routing/route';
export default Route.extend({
model(params) {
return this.store.findRecord('user', params.user_id);
}
});
我一直在关注 tutorialspoint.com 上的 EmberJS 教程,并且正在浏览“routes”部分,当我遇到 this page. It explains how to use dynamic segments in ember. So far I understand the code on how the route.js is updated and how the hbs file is created etc. (that's all pretty straightforward). What I don't understand is the last part where a serialize hook is made. I understand the code, but don't exactly know in which file should I put it? There is no mention of it in the tutorial, and I searched Whosebug as well but the only answer relevant to this was this 时解释它们是如何工作的而不是在哪里添加它们。有人可以解释一下我应该在哪个文件中添加这段代码吗?谢谢
查看 emberjs api。 serialize(model) 是 class 路由的一种方法。通常您不必实现该方法,因为在大多数情况下默认实现就足够了。默认实现将模型的 ID 添加为定义路由的动态段。
//router
Router.map(function() {
this.route('user', { path: '/user/:user_id' }); //user_id is the dynamic segment
});
//route with default serialize implementation
import Route from '@ember/routing/route';
export default Route.extend({
model(params) {
return this.store.findRecord('user', params.user_id);
}
});