灰烬数据自举模型对象 [英] Ember-data bootstrapping model objects

查看:67
本文介绍了灰烬数据自举模型对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用不是来自远程AJAX调用的现有JSON引导Ember数据模型对象时,我是否必须进行以下2次调用:

  App.store.load(App.Account,data); 
var account = App.store.find(App.Account,data.id);

是否不可能像调用一样一步创建对象setProperties 在现有的Ember对象上?



此外,如何创建Ember模型对象集合?例如:

  var users = App.get(‘users’); 
App.store.loadMany(App.User,users);
this.set('content',App.store.findMany(App.User,users.mapProperty('id')。uniq()));

以上似乎是错误的。我该如何从现有的JSON对象创建这些对象?

解决方案

对于我来说,似乎很好,就像 store一样。 load * 返回除模型对象(已加载的 ids & clientIds )以外的其他内容。 / p>

到目前为止,我认为别无选择。


When bootstrapping Ember-data model objects with existing JSON that is not from a remote AJAX call, do I have to make the following 2 calls:

App.store.load(App.Account, data);
var account = App.store.find(App.Account, data.id);

Is it not possible to create the Object in one step, similar to calling setProperties on an existing Ember object?

Also, how would this work for creating a collection of Ember model objects? For example:

var users = App.get('users');
App.store.loadMany(App.User, users);
this.set('content', App.store.findMany(App.User, users.mapProperty('id').uniq()));

The above seems wrong. How can I create these objects from existing JSON objects?

解决方案

Seems ok to me, as store.load* returns something else than model objects (loaded ids & clientIds).

So far, I think there is no alternative.

这篇关于灰烬数据自举模型对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆