Javascript 在路由代码运行和模板呈现之间,余烬模型的日期属性变为空
我在Ember应用程序中保存模型上的日期属性并使其保持不变时遇到问题。我的模型的编辑页面dataset.edit有一个保存操作,该操作应将模型的updatedAt属性设置为当前时间,保存模型,然后转换到显示模型新属性dataset.index的页面。保存操作中的日志代码显示,此时日期值设置正确,尽管Ember inspector神秘地报告日期属性为空,即使在调用model.save之后也是如此 当应用程序转换到dataset.index以向用户显示模型的新属性时,模型在路由的模型挂钩中已正确设置其日期,但当模板呈现时,所有模型的日期属性都将变为空!从模板或控制器获取日期属性的任何尝试都只会看到空值。。。即使这些相同的日期属性在路由的模型挂钩运行时设置正确。这怎么可能 以下是我代码的相关部分:Javascript 在路由代码运行和模板呈现之间,余烬模型的日期属性变为空,javascript,ember.js,ember-data,Javascript,Ember.js,Ember Data,我在Ember应用程序中保存模型上的日期属性并使其保持不变时遇到问题。我的模型的编辑页面dataset.edit有一个保存操作,该操作应将模型的updatedAt属性设置为当前时间,保存模型,然后转换到显示模型新属性dataset.index的页面。保存操作中的日志代码显示,此时日期值设置正确,尽管Ember inspector神秘地报告日期属性为空,即使在调用model.save之后也是如此 当应用程序转换到dataset.index以向用户显示模型的新属性时,模型在路由的模型挂钩中已正确设置
DataGatherer.ApplicationSerializer = DS.LSSerializer.extend();
DataGatherer.ApplicationAdapter = DS.LSAdapter.extend({
namespace: 'DataGatherer'
});
App.Dataset = DS.Model.extend({
// The time at which this model was last updated.
updatedAt: DS.attr('date')
});
App.DatasetEditRoute = Ember.Route.extend({
model: function() {
return this.modelFor('dataset');
}
});
App.DatasetEditController = Ember.ObjectController.extend({
actions: {
save: function() {
var self = this;
var dataset = this.get('model');
dataset.set('updatedAt', new Date());
// DEBUG
console.log("After setting Dataset.updatedAt:");
console.log(dataset.get('updatedAt')); // correctly prints the date
}
dataset.save().then(function() {
// DEBUG
console.log("After saving:");
console.log(dataset.get('updatedAt')); // correctly prints the date
self.transitionToRoute('dataset.index', dataset);
});
}
});
App.DatasetRoute = Ember.Route.extend({
model: function(params){
return this.store.find('dataset', params.dataset_id);
}
});
App.DatasetIndexRoute = Ember.Route.extend({
model: function() {
// DEBUG
var model = this.modelFor('dataset');
console.log('After loading new route:');
console.log(model.get('updatedAt')); // correctly prints the date
return this.modelFor('dataset');
}
});
App.DatasetIndexController = Ember.ObjectController.extend({
actions: {
whatsTheDate: function() {
// DEBUG
console.log("Dataset.updatedAt:");
console.log(this.get('model').get('updatedAt')); // when invoked prints null!
}
}
});