1

Ember 数据中是否有 findMany 方法?我需要手动调用它 - 例如,

App.Person.findMany([1, 2, 3]);

我一直在附加到商店或模型的帖子/博客/示例中看到它,但它没有出现在我的应用程序中。

  • 如果实现了,我该如何使用它?

  • 如果没有,有人可以指出我如何实施它的正确方向吗?

4

2 回答 2

1

您可以传递类似 App.Post.find({ids: [1,2,3]}) 的内容,它将查询:

/posts?ids%5B%5D=1&ids%5B%5D=2&ids%5B%5D=3

在 rails(或插入您选择的服务器语言)中,您可以执行以下操作:

 class PostsController < ApplicationController
  def index
    if ids = params[:ids]
      @posts = Post.where(:id => ids)
    else
      @posts = Post.scoped
    end

    respond_with @posts
  end
end

还有其他一些方法可以实现这一点,但由于 Ember Data 会不时更改,这种方法往往不会中断。

于 2013-07-30T17:18:01.533 回答
1

我不知道是否有别名findMany,但您可以直接使用商店。现场演示http://jsfiddle.net/marciojunior/sxLf3

store.findMany(App.User, [2,3]);
于 2013-07-30T17:19:10.243 回答