My application is connected to REST Api. In my setting page i had always only setting items of string type, but now i have also inputs of new type. on the new type i got the error:
Uncaught TypeError: Cannot read property 'serialize' of undefined
and no API call sent. more to that, all the GET calls are working just fine.
my adapter:
import ApplicationAdapter from 'nativeflow/adapters/application';
//application adapter extend DS.ActiveModelAdapter
export default ApplicationAdapter.extend({
buildURL: function(type, id, snapshot) {
var baseURL = this._super(type, id, snapshot);
if (typeof id !== 'undefined') {
baseURL = baseURL.replace('/' + id, '');
}
return baseURL;
}
});
my model:
import DS from 'ember-data';
export default DS.Model.extend({
type: DS.attr('string'),
value: DS.attr('setting')
});
serilizer:
import CountlessSerializer from 'nativeflow/serializers/countless-serializer';
// CountlessSerializer Extend another serilize and he extend DS.ActiveModelSerializer
import Ember from 'ember';
export default CountlessSerializer.extend({
primaryKey: 'key',
serialize: function(snapshot, options) {
var json = {};
var type = snapshot.attr('type');
var transform = this.transformFor(type, true);
json[snapshot.id] = transform.serialize(snapshot.attr('value'));
return json;
},
applyTransforms: function(type, data) {
type.eachTransformedAttribute(function applyTransform(key, type) {
if (!data.hasOwnProperty(key)) { return; }
var transform = this.transformFor(type);
data[key] = transform.deserialize(data[key], data['type']);
}, this);
return data;
},
attrs: {
id: {
serialize: function(dirtyType) {
return false;
}
},
type: {
serialize: function(dirtyType) {
return false;
}
}
}
});
my transform:
import DS from 'ember-data';
import Ember from 'ember';
export default DS.Transform.extend({
deserialize: function(serialized, type) {
var transform = this.transformFor(type, true);
return transform.deserialize(serialized);
},
serialize: function(deserialized, type) {
var transform = this.transformFor(type, true);
return transform.serialize(deserialized);
},
transformFor: function(attributeType, skipAssertion) {
var transform = this.container.lookup('transform:' + attributeType);
// Fallback to string if no transformer found
if (Ember.isNone(transform)) {
transform = this.container.lookup('transform:string');
}
Ember.assert("Unable to find transform for '" + attributeType + "'", true || !!transform);
return transform;
}
});
that is a wide application so i coud't up[load it to fidle. after hours of search, ill be grateful to the helpers!
Aucun commentaire:
Enregistrer un commentaire