在Ember视图中获得结果(Getting Results in Ember Views)

系统教程 行业动态 更新时间:2024-06-14 16:59:17
在Ember视图中获得结果(Getting Results in Ember Views)

因此,让所有Emberjs的东西在一起玩得很好已经有好几天了。 我真的很喜欢这个旅程,但是我不时地开始觉得这样做了。

所以我有一个应用程序点击/#/ Records链接。 从他们需要查询Rails,返回结果,然后抓住其他页面上的显示视图。 当我把它作为一个页面应用程序,在页面上有视图时,我让它工作....现在最近两天,混乱已经悄悄进入。(视图中的一些额外位被删除了。

我的hbs记录/索引视图文件部分显示:

<table> <tr> <th>Name</th> <tr> <td colspan="3">{{counter}}</td> </tr> </tr> {{#each record in controller}} <tr> <td>{{#linkTo "record" record}} {{record.fullName}} {{/linkTo}}</td> </tr> {{/each}} </table>

我的Ember App:

App = Ember.Application.create({ rootElement: '#ember' }); App.RecordsController = Ember.ArrayController.extend({ }); App.Store = DS.Store.extend({ revision: 11, adapter: 'DS.RESTAdapter' }); App.Record = DS.Model.extend({ firstName: DS.attr('string'), middleName: DS.attr('string'), surname: DS.attr('string'), suffix: DS.attr('string'), }) App.Router.map(function(){ this.resource('records'); this.resource('record', {path: 'records/:record_id'}) }); App.IndexRoute = Ember.Route.extend({ redirect: function(){ this.transitionTo('records') } }); App.RecordsRoute = Ember.Route.extend({ });

So it has been a long couple of days to get all the Emberjs stuff to play nice together. I really like this journey, but from time to time am beginning to feel to old to do this.

So I have a app hits the /#/Records link. From their It needs to query Rails, return the results, and then grab the show view on the other pages. When I had this as a single page app, with the views on the page, I had it working.... Now the last 2 days, confusion has crept in. (some extra bits in views and such are removed.

My hbs records/index view file which is partially showing up:

<table> <tr> <th>Name</th> <tr> <td colspan="3">{{counter}}</td> </tr> </tr> {{#each record in controller}} <tr> <td>{{#linkTo "record" record}} {{record.fullName}} {{/linkTo}}</td> </tr> {{/each}} </table>

My Ember App:

App = Ember.Application.create({ rootElement: '#ember' }); App.RecordsController = Ember.ArrayController.extend({ }); App.Store = DS.Store.extend({ revision: 11, adapter: 'DS.RESTAdapter' }); App.Record = DS.Model.extend({ firstName: DS.attr('string'), middleName: DS.attr('string'), surname: DS.attr('string'), suffix: DS.attr('string'), }) App.Router.map(function(){ this.resource('records'); this.resource('record', {path: 'records/:record_id'}) }); App.IndexRoute = Ember.Route.extend({ redirect: function(){ this.transitionTo('records') } }); App.RecordsRoute = Ember.Route.extend({ });

最满意答案

修改您的记录路线,如下所示。 此模型钩子为您提供了一种指定控制器如何获取其内容/模型的方法。 现在,当您查看网络选项卡时,您应该看到一个ajax请求,用于从后端获取所有记录(通过ember-data)

App.RecordsRoute = Ember.Route.extend({ model: function() { return App.Record.find(); } });

Modify your records route to look like the below. This model hook provides you a way to specify how a controller will get it's content / model. Now when you view the network tab you should see an ajax request to fetch all the records from your backend (via ember-data)

App.RecordsRoute = Ember.Route.extend({ model: function() { return App.Record.find(); } });

更多推荐

本文发布于:2023-04-16 14:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/70a0068dc729518eba574a70ace1cdaf.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   Ember   Views   Results

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!