Reputation: 47
I am a beginner in Ember.js and I would like to get a response result and show in my view (HTML).
My Result:
{"teste": { "code": "1", "message": "hello" } }
My controller in Ember.js:
actions: {
discountCoupon: function() {
var lista = _this.store.find('teste', { "param": "123" });
console.info("return=" + lista.get('code'));
// result return===undefined
console.info("return===" + lista.get('message'));
// result return===undefined
},
...
}
My model:
import DS from 'ember-data';
export default DS.Model.extend({
code: DS.attr('string'),
message: DS.attr('string'),
});
I can't get the return of my backend.
Thanks in advance.
Upvotes: 0
Views: 75
Reputation: 866
first you need to go and find what ever you are looking for, then you get your results. Remember When javascript promise
you something will always give you a result back back....
actions: {
discountCoupon: function(){
var listas = _this.store.find('testes', {
param: "123"
}).then(function(lista){
console.log("return=" + lista.get('code'));
console.log("return===" + lista.get('message'));
});
},
Upvotes: 2
Reputation: 126
One more thing, because you're using Ember Data and try to search using store.find('model', { queryParams })
Ember expects the backend to return a result in plural:
{"testes": [{"code":"1","message":"hello"}}]
Upvotes: 0