Created
December 12, 2016 20:06
-
-
Save JonathanVeg/f290f61438c2966187debdfb5b2ecc99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Service.extend({ | |
hour: -1, | |
// resumo dos problemas ocorridos naquela hora | |
resume_hour: [], | |
init(...params) { | |
this._super(params); | |
console.log("iniciando service"); | |
}, | |
setHour(hour) { | |
this.set('hour', hour); | |
// esse self aqui me deu acesso ao this dentro da promise | |
// era sooo isso | |
let self = this; | |
let url = '/api/resume_hour/' + hour; | |
let promise = new Promise(function(resolve, reject) { | |
resolve($.getJSON(url)); | |
}); | |
promise.then(function(json) { | |
// resolve | |
console.log("JSON"); | |
console.log(json); | |
Ember.set(self, "resume_hour", json.data); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment