在Ember视图中获取结果 [英] Getting Results in Ember Views
问题描述
因此,花了很长时间才使所有Emberjs玩法融为一体。我真的很喜欢这次旅行,但是时不时地开始这样做。
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.
所以我有一个应用程序命中了/#/ Records链接。从It需要查询Rails,返回结果,然后在其他页面上获取show视图。
当我将其作为单页应用程序使用时,在页面上具有视图,我就可以使用它。...现在最近两天,混乱逐渐蔓延开来。(视图中的一些多余内容已被删除)
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.
我的hbs记录/索引视图文件部分显示:
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>
我的Ember应用程序:
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)从后端获取所有记录
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();
}
});
这篇关于在Ember视图中获取结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!