在不共享父资源/路由的资源/路由之间共享模型数据的最佳方法(Ember方法)是什么?
细节:
我有2个顶级资源(resource1和resource2),它们的模型挂钩通过Ajax检索几乎相同的数据,因此它们的模型挂钩代码看起来也几乎相同,即不是很干。不同之处在于它们各自对数据进行处理。
目标:保留resource1和resource2顶级资源(或至少使其URL看起来像是顶级资源),让它们共享一些模型数据而不复制模型挂钩代码。
资源/路由定义:
App.Router.map(function () {
...
this.resource("resource1", function () {
this.route("routeA");
this.route("routeB");
});
this.resource("resource2", function () {
this.route("routeA");
this.route("routeB");
});
...
}
所需的URL:
example.com/#/resource1/routeA
example.com/#/resource1/routeB
example.com/#/resource2/routeA
example.com/#/resource2/routeB
NOT [嵌套在公共资源中]是这样的:
example.com/#/resource0/resource1/...
example.com/#/resource0/resource2/...
提前致谢!
这是对我有用的东西:
App.Router.map(function () {
...
this.resource("resource0", { path: "/" }, function () {
this.resource("resource1", function () {
this.route("routeA");
this.route("routeB");
});
this.resource("resource2", function () {
this.route("routeA");
this.route("routeB");
});
}
...
}
将resource0的路径指定为“ /”实际上会从URL路径中删除“ resource0”,从而使resource1和resource 2看起来像顶级资源。然后,我将来自resource1和resource 2的所有重复的模型挂钩代码分解为resource0的模型挂钩。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句