Rest 如何使用主干在解析函数中返回不同的数据类型

Rest 如何使用主干在解析函数中返回不同的数据类型,rest,parsing,backbone.js,Rest,Parsing,Backbone.js,我有一个web服务,它返回文档列表和列表大小。 我在web服务中的方法如下所示: public PaginatedJaxbList<DocumentDTO> listDocuments(String currentPage, String name) { List<DocumentDTO> docs= getDocsManager.getDocs(currentPage, name); int size = getDocsManager.getDocsSi

我有一个web服务,它返回文档列表和列表大小。 我在web服务中的方法如下所示:

public PaginatedJaxbList<DocumentDTO> listDocuments(String currentPage, String name) {
    List<DocumentDTO> docs= getDocsManager.getDocs(currentPage, name);
    int size = getDocsManager.getDocsSize();
    PaginatedJaxbList<DocumentDTO> docList = new PaginatedJaxbList<DocumentDTO>(docs, size);
    return docList;
}
@WebService
@Path("/docs")
public interface docService {

@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8")
public PaginatedJaxbList<DocumentDTO> listDocs(@QueryParam("p") String currentPage, @QueryParam("name") String name);
}
在parse函数中,我需要获得两个参数,即要显示的列表以及动态分页需要的列表大小


如何执行此操作?

集合解析方法应返回一个对象数组,将创建一个与数组中的每个项对应的模型,或一个对象,在这种情况下,将创建单个模型

因此,您应该只返回数组,但可以将其他属性附加到稍后要访问的集合,如下所示:

Entities.DocumentCollection = Backbone.Collection.extend({
    url : "../services/api/docs",
    model : Entities.Document,
    comparator : "name",
    parse : function(data) {
        this.size = data.size; // add size as a collection property
        return data.list; // return the list from which models should be populated
    }
});
Entities.DocumentCollection = Backbone.Collection.extend({
    url : "../services/api/docs",
    model : Entities.Document,
    comparator : "name",
    parse : function(data) {
        this.size = data.size; // add size as a collection property
        return data.list; // return the list from which models should be populated
    }
});