我正试图在Ember中做一个旋转木马滑块,但我已经在堆栈了,因为我无法让Ember获取我的图像。这是我的代码:
应用程序:
window.ArtRank = Ember.Application.create();
ArtRank.ApplicationAdapter = DS.FixtureAdapter.extend();
路由器:
ArtRank.Router.map(function (){
this.resource('index', {path: '/'}, function() {
this.resource("home", {path: '/'}, function() {
this.resource("photo", {path: '/photo'});
});
this.resource('categories', { path: "/categories" });
this.resource('profile', { path: "/profile" });
});
});
ArtRank.PhotoRoute = Ember.Route.extend({
model: function() {
return this.store.find('photo');
}
});
型号:
ArtRank.Photo = DS.Model.extend({
imageTitle: DS.attr('string'),
imageUrl: DS.attr('string')
});
ArtRank.Photo.FIXTURES = [
{
id: 1,
imageTitle: 'Learn Ember.js',
imageUrl: 'http://getbootstrap.com/2.3.2/assets/img/bootstrap-mdo-sfmoma-01.jpg'
},
{
id: 2,
imageTitle: '...',
imageUrl: 'http://getbootstrap.com/2.3.2/assets/img/bootstrap-mdo-sfmoma-01.jpg'
},
{
id: 3,
imageTtitle: 'Profit!',
imageUrl: 'http://getbootstrap.com/2.3.2/assets/img/bootstrap-mdo-sfmoma-01.jpg'
}
];
我的模板由以下人员制作:页眉和页脚以及{{outlet}}内的索引
Outelet调用home.hbs,即:{{局部照片}}
home.hbs渲染照片.hbs即:
<div class="photos-wrap">
<h1>{{ imageTitle }}</h1>
<div class="photoItem">
<img id="photoItem" {{bind-attr src="imageUrl"}} />
</div>
</div>
任何建议都非常感谢!
为了回答我自己的问题(所以它不会一直打开),它一切都很好,我只是不明白你需要进入特定的路由器来获取数据。我以为你可以在应用程序的任何地方获取它们,但当然,当你在特定的应用程序中时就会显示出来。
您在模板中遗漏了一个each,因为reute定义的模型挂钩的结果是数组
{{#each}}
<h1>{{ imageTitle }}</h1>
<div class="photoItem">
<img id="photoItem" {{bind-attr src="imageUrl"}} />
</div>
{{/each}}
此外,资源定义不正确,IMHO两条/路径。。。尝试类似的配置
this.resource('index', {path: '/'}, function() {
this.resource("home", {path: 'home'}, function() {
祝好运