2

我想通过数据模式传递我的完整 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
}
4

0 回答 0