gpt4 book ai didi

javascript - 检索当前用户的策略

转载 作者:搜寻专家 更新时间:2023-11-01 04:19:36 26 4
gpt4 key购买 nike

我正在寻找一种经典的策略来使用 emberjs(和 ember-data)检索当前用户信息。

目前,我在做以下事情:

我的 API 以当前用户响应 /users/me
在我的适配器中,当检索到的对象 id 不是我希望的那个时,我添加一个 real_id 这是 id(数据库中的用户 id),我替换真正返回的 id按照我的预期。

因此,当我的适配器将“我”作为用户 ID,但服务器返回 1 时,我得到以下 json:

{"real_id": 1, "id": "me"}

这行得通。但我不是忠实粉丝,我想尽可能避免更改适配器的默认内容。

您为此使用了任何策略吗?你会推荐什么?

最佳答案

我会为此使用 Controller App.currentUserController

App.CurrentUserController = Ember.ObjectController.extend({
content: null,

retrieveCurrentUser: function() {
var controller = this;
Ember.$.getJSON('/users/me', function(data) {
App.store.load(App.User, data);
var currentUser = App.store.find(data.id);
controller.set('content', currentUser);
});
}
});

关于javascript - 检索当前用户的策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9618395/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com