2

创建了一个输出 json 的 web api,尝试将它与backbone.js 分页插件一起使用,以将结果输出到backbone.js 无限分页插件

这是我输出的 json

    [{"id":1,"title":"test1""desc":"book1"},
    {"id":2,"title":"test2","desc":"book2"},
    {"id":3,"title":"test3", "desc":"book3"},
    {"id":4,"title":"test4","desc":"book4"},
    {"id":5,"title":"test5","desc":"book5"},
    {"id":6,"title":"test6","desc":"book6"}]

但我需要包含对象的名称,因为backbone.js 分页器需要返回响应对象。认为我几乎就在那里,但似乎无法让它显示或弄清楚我如何将对象名称添加到它?

 {"object name:"[{"id":1,"title":"test1","desc":"book1"},            {"id":2,"title":"test2","desc":"book2"},
{"id":3,"title":"test3","desc":"book3"},
{"id":4,"title":"test4","desc":"book4"},
{"id":5,"title":"test5","desc":"book5"},
{"id":6,"title":"test6","desc":"book6"}]}

public class latestnewsController : EntitySetController<news, int>
{
    onlinepressEntities _context = new onlinepressEntities();


    latestnewsController()
    {
        _context.Configuration.LazyLoadingEnabled = false;
    }

    [Queryable]
    public override IQueryable<news> Get()
    {
        return _context.news;

    }

    protected override news GetEntityByKey(int key)
    {
        return _context.news.FirstOrDefault(c => c.ID == key);
    }

    protected override void Dispose(bool disposing)
    {
        base.Dispose(disposing);
        _context.Dispose();
    }

}
4

1 回答 1

1

当您在客户端收到“新闻”时,将其添加为现有对象的属性。

var news = getNews();
var thing = { "object name" : news };
backbone(thing);
于 2014-01-17T07:45:53.720 回答