[英]Bootstrapping data models in Ember?
I would like to bootstrap an application with data without having to do an additional request. 我想用数据引导应用程序而无需另外请求。 Assuming I have a simple user model with the following json: 假设我有一个带有以下json的简单用户模型:
{"user":{"id":1,"email":"test@example.com"}}
This json is being dumped by a Rails app. 这个json正被Rails应用程序抛弃。 How best should I bootstrap my User
model in Ember? 我应该如何最好地在Ember中引导我的User
模型?
Use 使用
App.Store.load(App.YourModel, yourdata);
See this question: 看到这个问题:
Ember-data bootstrapping model objects Ember数据引导模型对象
edit: not sure if you can load multiple objects at once - you may have to loop your collection. 编辑:不确定是否可以一次加载多个对象 - 您可能需要循环收集。 Suggest using something like underscore.js 建议使用像underscore.js这样的东西
如果您的目标是从JSON引导模型,那么您应该使用push()方法,如下所示: http : //emberjs.com/guides/models/pushing-records-into-the-store/#toc_pushing-records
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.