I am using ember and trying to use an adapter to get a json response for the first time. Although the data is there in the console log it looks like the model is not retrieving the data.
In songs.js router I return the model...
export default Ember.Route.extend({
model: function(params){
console.log("This. ", this.get('store').findAll('songs'))
return this.get('store').findAll('songs')
}
});
In songs.js adapter I have my call...
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
findAll: function(store,type,id,snapshot){
return $.ajax({
url: 'http://ift.tt/1RjByBK',
dataType: 'jsonp',
success: function(response){
console.log("resp? ", response)
return response
}
}).then(function(data){
console.log("this is dfaataadgagafgaffg ", data)
return{
songs: {
resultCount: data.resultCount,
results: data.results
}
}
})
}
});
In songs.js model I have the modeled response...
import DS from 'ember-data';
export default DS.Model.extend({
resultCount: DS.attr('integer'),
results: DS.attr('array')
});
I also defined the array transform...
import DS from 'ember-data';
export default DS.Transform.extend({
deserialize: function(serialized) {
return (Ember.typeOf(serialized) == "array")
? serialized
: [];
},
serialize: function(deserialized) {
var type = Ember.typeOf(deserialized);
if (type == 'array') {
return deserialized
} else if (type == 'string') {
return deserialized.split(',').map(function(item) {
return jQuery.trim(item);
});
} else {
return [];
}
}
});
The result from the API is {resultCount:50, results: Array[50]} per the console log so I am unsure why this is not working. Any ideas?
Aucun commentaire:
Enregistrer un commentaire