Ember.js 如何使用本地存储适配器更新记录
对于我现在使用的本地存储适配器,我想在我的模型中更新一个id为'ab12'的模型,但我不知道如何更新它。我的模型是:Ember.js 如何使用本地存储适配器更新记录,ember.js,ember-data,Ember.js,Ember Data,对于我现在使用的本地存储适配器,我想在我的模型中更新一个id为'ab12'的模型,但我不知道如何更新它。我的模型是: OlapApp.AxisModel = DS.Model.extend({ uniqueName: DS.attr('string'), name: DS.attr('string'), hierarchyUniqueName: DS.attr('string'), type: DS.attr('string'),//row,column,filter isM
OlapApp.AxisModel = DS.Model.extend({
uniqueName: DS.attr('string'),
name: DS.attr('string'),
hierarchyUniqueName: DS.attr('string'),
type: DS.attr('string'),//row,column,filter
isMeasure: DS.attr('boolean'),
isActive:DS.attr('boolean'), //is added to one of type
orderId: DS.attr('number')
});
我是我的控制器我正在尝试:
this.get('store').updateRecord('axisModel',{
id:item.get('id'),
orderId:index
});
但我有一个错误:
Uncaught TypeError: Object [object Object] has no method 'updateRecord'
我需要更新模型中的orderId。如果我使用commit(),我会得到一个错误:
updateSortOrder: function(indexes) {
var store = this.get('store');
this.get('getRowItem').forEach(function(item) {
var index = indexes[item.get('id')];
if($.isEmptyObject(indexes)) index=0;
item.set('orderId', index);
store.commit();
}, this);
},
错误是:
Uncaught TypeError: Object [object Object] has no method 'commit'
这是getRowItem
:
getRowItem: function(controller, model) {
return this.get('model').filterProperty('type', 'row');
}.property('model.@each.type'),
您可以使用
DS.Model.save()
。在控制器中:
var model = this.get('content');
model.setProperties({
id:item.get('id'),
orderId:index
});
model.save().then(function() {
alert('saved');
}, function() {
alert('not saved');
});
这是假设Route
的model()方法返回了实例,或者您可以先使用find()
:
this.get('store')
.find('axisModel', id)
.then(function(model) {
model.save().then(...)
});
首先感谢您的回答。我尝试了model.setProperties()的第一种方法,但得到了一个错误
uncaughttypeerror:Object[Object Object]没有方法save
并且我正在使用第二种方法使用存储我得到这个错误未捕获类型错误:当我console.log model.get('uniqueName')时,无法在then方法的第二种方法调用未定义的方法查找。当我使用DS.Model.save()时,localStorage中没有发生任何事情,也没有任何更改。我认为所有这些错误都是因为本地存储适配器不支持上次的Ember数据版本