简体   繁体   English

在 ember.js 路由中使用设置控制器?

[英]Use of setupcontroller in ember.js route?

Do routes actually need to use setupcontroller() to load model to templete?路由是否真的需要使用 setupcontroller() 将 model 加载到模板? What is the use of setupcontroller?设置控制器有什么用?

Technically, yes, the setupController hook is where the actual data from the model hook is set to the controller instance of the current route from which the template layer can access the data.从技术上讲,是的, setupController挂钩是将model挂钩的实际数据设置为当前路由的controller实例的地方,模板层可以从中访问数据。 However, you don't need to do this in every route of your app as this is the default behaviour ( implementation ) of the framework.但是,您不需要在应用程序的每个路由中都执行此操作,因为这是框架的默认行为( 实现)。

If this behaviour is enough for you, there is no need to define this hook in your route.如果这种行为对你来说已经足够了,那么就不需要在你的路由中定义这个钩子了。 In case, you need to do some other operations before the page loads, you can use this hook.如果你需要在页面加载之前做一些其他的操作,你可以使用这个钩子。

for more info, here is the official API documentation which explains with an example.有关更多信息,这里是官方 API 文档,其中举例说明。

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

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