I am an Ember newbie and am trying to create a simple application to fetch records from an API server. Currently I am trying to query the
this.store.find('validemail',{'email':'abc.gmail.com'}).then(function(response){
console.log(response);
});
//Console log on browser
Class {query: Object, store: Class, manager: Class, isLoaded: true, meta: Object…}__ember1434866946710: "ember592"__ember_meta__: Object__nextSuper: undefinedcontent: (...)get content: GETTER_FUNCTION() {set content: SETTER_FUNCTION(value) {isLoaded: truemanager: Classmeta: Objectquery: Objectstore: Classtype: client@model:validemail:__proto__: Class
This is a lot of data but I am not able to make any sense of it,all I want is a success:true or success:method from the server API.
Here is my Model class import DS from 'ember-data';
export default DS.Model.extend({
success:DS.attr('boolean'),
message: DS.attr('string')
});
and the API method
router.get('/validemails',function(req,res){
console.log(req.query);
var useremail=req.query.email;
Hiveuser.find({'useremail':useremail},function(err,findResponse){
if(!isEmptyObject(findResponse)){
res.send({"validemail": {success: false,'message': 'User Already Exists'}});
}
else{
res.send({"validemail": {success: true,'message':''}});
}
});
});
I realize that I am doing something wrong because Ember Inspector shows 0 records for the model class. What I don't get is logging the server response shows that the correct response is sent from the server but somehow it gets mangled into this garbled text into the client. Note: I did not even intend to use Ember Models for this simple use case ,but sending a jQuuery GET request would require me to hardcode server IP into the controller ,hence had to go the Adapter "route"(No pun intended :) ) If there is a way I can send a JSON request from the contoller which would take the server ip from the Adapter I'd very much like to know about it. Thanks
Aucun commentaire:
Enregistrer un commentaire