繁体   English   中英

灰烬数据:无法从模板访问模型数据

[英]Ember Data: Can't access model data from template

因此,我几天以来一直对此表示怀疑。 我根本无法在模型中渲染模型数据。 没有引发任何错误,当我在模板中插入{{model}}{{controller}}时,我得到了对DS和Ember对象, <DS.RecordArray:ember411><App.FamilyController:ember438>

在Ember Inspector中查看,“数据”选项卡显示我的记录加载到各个族中,如果我单击对象引用,然后单击“成员/帖子”字段,它也加载了成员/帖子...因此检查员至少似乎正确地获取了数据,但是模板却没有。 任何帮助,不胜感激。

js / routes / family.js.coffee App.FamilyRoute = Ember.Route.extend model: -> @store.find 'family'

js / templates / family.hbs <img {{bind-attr src=img}} alt="Profile"> <h1>{{name}} Family</h1> <p>{{description}}</p> {{families}} {{controller}}

js / controllers / family.js.coffee App.FamilyController = Ember.ObjectController.extend({})

js / models / family.js.coffee App.Family = DS.Model.extend name: DS.attr('string') description: DS.attr('string') img: DS.attr('string') members: DS.hasMany('member', {async: true}) posts: DS.hasMany('post', {async: true}) API { "families": [{ "id": 2, "name": "Weebleson", "description": "Bob, Jill, Jane, John and Spot.", "img": "/images/weebleson.jpg", "member_ids": [6, 5, 4], "post_ids": [61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80] }] } API中的 App.Family = DS.Model.extend name: DS.attr('string') description: DS.attr('string') img: DS.attr('string') members: DS.hasMany('member', {async: true}) posts: DS.hasMany('post', {async: true}) json { "families": [{ "id": 2, "name": "Weebleson", "description": "Bob, Jill, Jane, John and Spot.", "img": "/images/weebleson.jpg", "member_ids": [6, 5, 4], "post_ids": [61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80] }] }

Ember : 1.8.1 Ember Data : 1.0.0-beta.14.1 Handlebars : 1.0.0 jQuery : 1.11.1

this.store.find @store.find中的this.store.find@store.find返回商店中的所有模型。 因此,默认情况下,您将获得模型列表 看起来该列表中将有一个家庭。

如果要在列表中显示,可以使用{{#each family in families}}{{family.name}}{{/each}}

仅在您获得一定的ID FamilyRoute ,您可以使用@store.find('family', id) 因此,示例为@store.find('family', 2) 这将达到另一个终点。

如果要返回第一个结果,则可以使用find返回的promise:

@store.find('family').then (family) -> family.get('firstObject')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM