我试图在商店内登录后存储一些数据。下面是我的torii-adapter
的代码import Ember from 'ember';
import {createToken} from 'myapp/utils/app-utils';
export default Ember.Object.extend({
store: Ember.inject.service(),
open: function(authentication){
let authorizationCode = authentication.authorizationCode;
let token = createToken();
return new Ember.RSVP.Promise(function(resolve, reject){
console.log(authentication);
Ember.$.ajax({
url: 'http://localhost/getUserInfoWuthAuthCode.php',
data: { 'code': authorizationCode,token:token},
success: Ember.run.bind(null, resolve),
error: Ember.run.bind(null, reject)
});
}).then(function(data){
let user = data.user[0];
this.set('storage.token',token); //this is undefined
return {
user: user
};
});
}
});
我得到的错误是“TypeError:无法读取未定义的属性'set'”。 我也在注入商店服务。你能告诉我这里到底出了什么问题吗?
答案 0 :(得分:0)
答案 1 :(得分:0)
另一种方法是使用ES6箭头功能,这样就不需要为其他变量分配 open: function(authentication){
let authorizationCode = authentication.authorizationCode;
let token = createToken();
let that = this;
return new Ember.RSVP.Promise((resolve, reject) => {
console.log(authentication);
Ember.$.ajax({
url: 'http://localhost/getUserInfoWuthAuthCode.php',
data: { 'code': authorizationCode,token:token},
success: Ember.run.bind(null, resolve),
error: Ember.run.bind(null, reject)
});
}).then((data) => {
let user = data.user[0];
that.set('storage.token',token);
return {
user: user
};
});
}
。
{{1}}
Ember-cli将帮助您将ES6转换为ES5,使其与大多数浏览器兼容。