具有多个json元素的Kendo数据源模式

时间:2013-07-13 12:27:05

标签: jquery asp.net-mvc json asp.net-mvc-4 kendo-ui

我想通过数据模式传递我的完整json元素,并在数据源的fetch函数中使用它。我一直在浏览Telerik的文档,找不到符合我需求的示例,也许我认为这种用法不对。这实际上是否可以使用Kendo数据源?

### DerpController ###

public ActionResult GetDerps(string derpNumber)
{
    List<Derp> derps = _getDerps();
    List<Derpina> derpinas = _getDerpinas();
    var generic = new {Derps = derps, Derpinas = derpinas};
    return Json(generic);
}

### jQuery ###

//These are populated correctly through the schema but I would like to skip using 
//these variables and pass the elements with the data schema (if possible)
var derps;
var derpinas;

var systDataSource = new kendo.data.DataSource({
    transport: {
        read: {
            type: "POST",
            dataType: "json",
            url: 'Derp/GetDerps/',
            data: {
                derpNumber: derpNumber
            }
        }
    },
    schema: {
        data: function (response) {
            //This works fine if I use the variables above
            derps= response.Derps;
            derpinas= response.Derpinas;
            return response;
        }
    }
});

systDataSource.fetch(function () {
    var data = this.data();
    //I would like to be able to do something like this
    var theDerps = data.derps;

    //stuff abbreviated
}

0 个答案:

没有答案