Javascript 无余烬数据的余烬动态段
我正在为路线的动态部分而挣扎。这是我的密码Javascript 无余烬数据的余烬动态段,javascript,ember.js,ember-data,Javascript,Ember.js,Ember Data,我正在为路线的动态部分而挣扎。这是我的密码 App.Router.map(function(){ this.resource('stuff', {path: '/stuff/:stuff_id'}, function() { this.route('make'); this.route('edit'); this.route('delete'); this.route('history
App.Router.map(function(){
this.resource('stuff', {path: '/stuff/:stuff_id'}, function() {
this.route('make');
this.route('edit');
this.route('delete');
this.route('history');
});
});
App.StuffRoute = Ember.Route.extend({
model: function(param) {
},
setupController: function (){
},
renderTemplate: function() {
}
});
App.StuffView= Ember.View.extend({
defaultTemplate: Ember.Handlebars.compile(stuffTemplate)
});
App.StuffController = Ember.Controller.extend();
我应该在
StaffRoute
的模型中添加什么内容,使我不再得到与URL“危机”匹配的任何路径
错误?对于localhost/#stuff
以及如何正确设置动态段部分?我对ember文档的唯一问题是,所有示例都使用未准备好生产的ember数据,我不想使用它 如果没有ember数据,您通常会将带有jQuery的直接getJSON放在路由的model
方法中。model
方法支持承诺,因此可以重用jQuery承诺
例如,给定使用Flickr api为/images/tag
路由加载图像列表的路由
App.Router.map(function() {
this.resource('images', { path: '/images/:tag'});
});
App.ImagesRoute = Ember.Route.extend({
model: function(params) {
flickerAPI = 'http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?';
console.log('ImagesRoute.model', params);
return jQuery.getJSON( flickerAPI, {
tags: params.tag,
tagmode: 'any',
format: "json"
})
.then(function(data) {
console.log('loaded images', data);
return data;
})
.then(null, function() { console.log('failed to load images'); });
}
});
相应的控制器可以自动访问/绑定返回的json的属性。或者,您可以为几个计算属性设置别名
App.ImagesController = Ember.ObjectController.extend({
images: function() {
return this.get('model').items;
}.property('controller'),
title: function() {
return this.get('model').title;
}.property('images')
});
<script type='text/x-handlebars' data-template-name='images'>
<h1>{{title}}</h1>
{{#each image in images}}
<img {{bindAttr src='image.media.m'}} />
{{/each}}
</script>
然后使用这些属性通过把手进行渲染
App.ImagesController = Ember.ObjectController.extend({
images: function() {
return this.get('model').items;
}.property('controller'),
title: function() {
return this.get('model').title;
}.property('images')
});
<script type='text/x-handlebars' data-template-name='images'>
<h1>{{title}}</h1>
{{#each image in images}}
<img {{bindAttr src='image.media.m'}} />
{{/each}}
</script>
{{title}}
{{#图像中的每个图像}
{{/每个}}
这里有一个可以做到这一点的方法。如果没有余烬数据,您通常会将带有jQuery的直接getJSON放在路由的
model
方法中。model
方法支持承诺,因此可以重用jQuery承诺
例如,给定使用Flickr api为/images/tag
路由加载图像列表的路由
App.Router.map(function() {
this.resource('images', { path: '/images/:tag'});
});
App.ImagesRoute = Ember.Route.extend({
model: function(params) {
flickerAPI = 'http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?';
console.log('ImagesRoute.model', params);
return jQuery.getJSON( flickerAPI, {
tags: params.tag,
tagmode: 'any',
format: "json"
})
.then(function(data) {
console.log('loaded images', data);
return data;
})
.then(null, function() { console.log('failed to load images'); });
}
});
相应的控制器可以自动访问/绑定返回的json的属性。或者,您可以为几个计算属性设置别名
App.ImagesController = Ember.ObjectController.extend({
images: function() {
return this.get('model').items;
}.property('controller'),
title: function() {
return this.get('model').title;
}.property('images')
});
<script type='text/x-handlebars' data-template-name='images'>
<h1>{{title}}</h1>
{{#each image in images}}
<img {{bindAttr src='image.media.m'}} />
{{/each}}
</script>
然后使用这些属性通过把手进行渲染
App.ImagesController = Ember.ObjectController.extend({
images: function() {
return this.get('model').items;
}.property('controller'),
title: function() {
return this.get('model').title;
}.property('images')
});
<script type='text/x-handlebars' data-template-name='images'>
<h1>{{title}}</h1>
{{#each image in images}}
<img {{bindAttr src='image.media.m'}} />
{{/each}}
</script>
{{title}}
{{#图像中的每个图像}
{{/每个}}
这里有一个可以执行此操作的方法。
'/stuff/:stuff_id'
只匹配/stuff/something
,而不匹配'/stuff'
尝试定义单独的资源:
App.Router.map(function(){
this.resource('stuffs', {path: '/stuff'});
this.resource('stuff', {path: '/stuff/:stuff_id'}, function() {
// routes ...
});
或
并对该资源使用
App.StuffsRoute
、App.StuffsView
和App.StuffsController
。'/stuff/:stuff\u id'
只匹配/stuff/something
,而不匹配/stuff'
尝试定义单独的资源:
App.Router.map(function(){
this.resource('stuffs', {path: '/stuff'});
this.resource('stuff', {path: '/stuff/:stuff_id'}, function() {
// routes ...
});
或
并使用此资源的App.StuffsRoute
、App.StuffsView
和App.StuffsController