这适用于ember-data-0.0.14:
// Used to represent a list of strings, for example the multilocators: [ "43534545354", "4356346" ]
// Used for phone_numers, emails and addresses
// See http://stackoverflow.com/a/18019074/647991
SettingsApp.register('transform:listOfStringsTransform', {
serialize: function(data) {
var elements = [];
for (var i = 0; i < data.length; i++) {
elements.push(data[i]);
}
if (DEBUG) { console.log('listOfStringsTransform.serialize > data=%o -> elements=%o', data, elements); }
return elements;
},
deserialize: function(elements) {
var data = Ember.A();
for (var i = 0; i < elements.length; i++) {
data.push(elements[i]);
}
if (DEBUG) { console.log('listOfStringsTransform.deserialize > elements=%o -> data=%o', elements, data); }
return data;
}
});
但是现在,我得到了:
Error while loading route: TypeError: Object #<Object> has no method 'create'
at instantiate (http://localhost:9001/bower/ember/ember.js:10975:26)
at Object.Container.lookup (http://localhost:9001/bower/ember/ember.js:10547:21)
at DS.JSONSerializer.Ember.Object.extend.transformFor (http://localhost:9001/bower/ember-data/ember-data.js:869:36)
at null.<anonymous> (http://localhost:9001/bower/ember-data/ember-data.js:206:28)
at http://localhost:9001/bower/ember-data/ember-data.js:5780:16
at http://localhost:9001/bower/ember/ember.js:3194:16
at Object.OrderedSet.forEach (http://localhost:9001/bower/ember/ember.js:3037:10)
at Object.Map.forEach (http://localhost:9001/bower/ember/ember.js:3192:10)
at Function.DS.Model.reopenClass.eachTransformedAttribute (http://localhost:9001/bower/ember-data/ember-data.js:5779:40)
at DS.JSONSerializer.Ember.Object.extend.applyTransforms (http://localhost:9001/bower/ember-data/ember-data.js:205:10) ember.js:3287
在ember-data代码库中有一个针对寄存器变换的测试,这非常简单,所以它不能作为参考。如何将此工作代码调整为新的余烬数据?
答案 0 :(得分:0)
转换必须是DS.Transform.extend({})