我正在尝试做的事情: 创建一条记录,暂时不要持久化,因为一些需要的信息会在下一条路线上填写。
我怎么做到的? 我正在生成一个 uuid,并将其分配给记录。然后过渡到新路线。
createOrder() {
var d = new Date().getTime();
var uuid = 'xxxxyyyxxxxxxxxyyxyxxxyyy'.replace(/[xy]/g, function(c){
var r = (d + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);
return (c === 'x' ? r : (r & 0x7 | 0x8)).toString(16);
});
console.log(uuid)
this.get('model.event.orders').addObject(this.store.createRecord('order', {id:uuid}));
this.transitionToRoute('orders.list.new', uuid);
问题:
URL 符合预期 /orders/<order:id>/new
但,
转换后,模型会尝试从返回 404 的服务器获取数据,而不是使用记录存在的本地存储或内存。
我想要什么? 我怎样才能让它使用本地存储,以免导致错误。
最佳答案
正如 Lux 在评论中所写,传递模型将解决您的问题。原因很简单:如果模型在 transitionToRoute 中作为参数给出函数,Ember 将使用该模型而不是从后端获取模型(通过调用 model hook
)。
来自文档:
Optionally supply a model for the route in question. The model will be serialized into the URL using the serialize hook of the route.
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
关于javascript - 在 Ember 的动态路由上使用非持久记录的正确方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46020335/