gpt4 book ai didi

ember.js - 重置路线模型

转载 作者:行者123 更新时间:2023-12-02 22:16:05 24 4
gpt4 key购买 nike

我有一条路线负责在财务应用程序中创建交易。当用户添加交易时,他们可能希望输入更多交易,这样我就不会离开。我的问题是,如何重置附加到路线的模型,使其成为全新的记录(我正在使用 ember 数据)?

最佳答案

保存记录后,通过调用路由的model()获取一条新记录,并将其设置到相应 Controller 的model属性中:

App.TransactionRoute = Ember.Route.extend({
model: function() {
return this.store.createRecord('transaction');
}

actions: {
save: function() {
var model = this.modelFor('transaction');
var controller = this.controllerFor('transaction');
var route = this;

model.save().then(function(){
var newModel = route.model();
controller.set('model', newModel);
});
}
}
});

关于ember.js - 重置路线模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22735587/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com