还有一个类似的问题.
假设以下路线:
App.Router.map(function (match) {
match('/').to('index');
match('/posts').to('posts', function (match) {
match('/').to('postsIndex');
match('/:post_id').to('post', function (match) {
match('/comments').to('comments', function (match) {
match('/').to('commentsIndex');
match('/:comment_id').to('showComment');
});
});
});
});
Run Code Online (Sandbox Code Playgroud)
是否可以访问post_id和comment_id进入ShowCommentRoute?否则我应该忘记模型中的复合键?
为什么CommentsRoute#model(params)和CommentsIndexRoute论点总是空的?如何在Post何时检索评论?
我的小提琴.
也运行此示例(有控制台日志显示问题.
经过一番调查后更新:
只会PostRoute有params.post_id.只会ShowCommentRoute有params.comment_id和不会有params.post_id.
对于模型具有复合键的应用程序,这是不可接受的.如果我们showComment一步一步过渡,我们可以获得Comment实例:
App.ShowCommentRoute = Ember.Route.extend({
model: function(params) {
var post_id = this.controllerFor('post').get('content.id');
return App.Comment.find(post_id, params.comment_id);
}
});
Run Code Online (Sandbox Code Playgroud)
但如果我们直接访问,这将无效 …
我在使用 ruby 从物化路径构建树结构时遇到问题。
假设我有一个排序结果集(来自 couchdb):
[
{ :key => [], :value => "Home" },
{ :key => ["about"], :value => "About" },
{ :key => ["services"], :value => "Services" },
{ :key => ["services", "plans"], :value => "Plans" },
{ :key => ["services", "training"], :value => "Training" },
{ :key => ["services", "training", "python"], :value => "Python" },
{ :key => ["services", "training", "ruby"], :value => "Ruby" }
]
Run Code Online (Sandbox Code Playgroud)
我只需要它作为 ruby 中的树,以下哈希就足够了:
{ :title => "Home", :path => [], :children …Run Code Online (Sandbox Code Playgroud) 我有一个API,不适合Ember-Data的Rest Adapter.大约有3个模型,因此我决定使用jQuery的普通旧的$ .ajax.在找到一种如何检索模型并以正确的方式将它们传递给控制器的方法时,我心烦意乱.
请从指南中考虑以下示例:
App.Router.map(function(match) {
match('/posts').to('posts');
});
App.PostsRoute = Ember.Route.extend({
model: function() {
return App.Post.findAll(); // Just renamed to .findAll.
}
});
Run Code Online (Sandbox Code Playgroud)
我发现.findAll方法必须返回一个E.ArrayProxy的实例,否则就不可能做到这样的事情:
{{#if content}}
...
{{else}}
<strong>Nothing to display</strong>
{{/if}}
Run Code Online (Sandbox Code Playgroud)
我的实现看起来如此:
App.Post.reopenClass({
findAll: function() {
var result = Ember.ArrayProxy.create({content: []});
$.getJSON('/posts', function(data) {
$.each(data, function(i, row) {
result.pushObject(App.Post.create(row));
});
});
return result;
}
});
Run Code Online (Sandbox Code Playgroud)
我对此非常满意,但我无法想象如何使用单个对象.
App.PostsRoute = Ember.Route.extend({
model: function(params) {
return App.Post.find(params.post_id);
}
});
// This will not work for me. Controller's content property will alway be …Run Code Online (Sandbox Code Playgroud)