transitionToRoute 重新加载模型
transitionToRoute reloading the model
如何转换到路线并告诉 Ember 重新加载该路线的模型?
我的用例:
我所在的页面是 appointment
。在我 cancel
约会之后,我需要转换到 /schedule
路线显示所有约会,除了我刚刚取消的那个。
当我使用transitionToRoute
时,已取消的约会仍在列表中。然后我必须重新加载浏览器页面才能看到新列表。
我完全同意@Kingpin2k在删除任命的评论中的建议。如果出于某种原因这对您不起作用 - 只需过渡到 路线而不 提供任何模型(省略第二个参数)或提供可以查找模型的 id,这是一个整数或一个字符串。然后将调用 Route
的 model
挂钩。
来自docs:
If a literal is passed (such as a number or a string), it will be treated as an identifier instead. In this case, the model hook of the route will be triggered
如果您在 transitionToRoute 中传递模型
在您要转换的模型路线中,使用设置控制器挂钩简单地重新加载模型
setupController: function(controller, model) {
model.reload();
controller.set('model', model);
},
model.reload()
是您可以在应用程序中随时刷新模型的方式。
如何转换到路线并告诉 Ember 重新加载该路线的模型?
我的用例:
我所在的页面是 appointment
。在我 cancel
约会之后,我需要转换到 /schedule
路线显示所有约会,除了我刚刚取消的那个。
当我使用transitionToRoute
时,已取消的约会仍在列表中。然后我必须重新加载浏览器页面才能看到新列表。
我完全同意@Kingpin2k在删除任命的评论中的建议。如果出于某种原因这对您不起作用 - 只需过渡到 路线而不 提供任何模型(省略第二个参数)或提供可以查找模型的 id,这是一个整数或一个字符串。然后将调用 Route
的 model
挂钩。
来自docs:
If a literal is passed (such as a number or a string), it will be treated as an identifier instead. In this case, the model hook of the route will be triggered
如果您在 transitionToRoute 中传递模型
在您要转换的模型路线中,使用设置控制器挂钩简单地重新加载模型
setupController: function(controller, model) {
model.reload();
controller.set('model', model);
},
model.reload()
是您可以在应用程序中随时刷新模型的方式。