HLeite
HLeite

Reputation: 47

Ember.js - Get Result

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

Answers (2)

Jose CC
Jose CC

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

Filipe Braganca
Filipe Braganca

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

Related Questions