2

Kendo UI Grid + DataSourceを使用していますが、サービスとのやり取りでいくつかの問題が発生しています。

次のように呼び出す必要があるサービスがあります。

 /find?criteria[0].FieldName=Name&criteria[0].Value=Test&criteria[1].FieldName=Description&criteria[1].Value=MyDescription

データソースからサービスにパラメータ自体を渡すにはどうすればよいですか?

4

2 に答える 2

4

parameterMap次のような関数を使用する必要があります。

var data = kendo.data.DataSource({
    transport: {
        // these are passed to $.ajax()
        read: {
            url: "/find",
            dataType: 'json',
            type: 'GET',
            cache: false
        },
        update: {
            // ...
        },
        destroy: {
            // ...
        },
        create: {
            // ...
        },
        //
        parameterMap: function(options, type) {
            // edit VARS passed to service here!
            if (type === 'read') {
                return {
                    'criteria[0].FieldName': options.name,
                    'criteria[0].Value': options.value
                    // ...
                };
            }
        }
    },

    schema: {
        model: MyModel,
        type: 'json',

        parse: function(response) {
            // edit VARS coming from the server here!
            // ...
            return response;
        }
    }
});
于 2012-09-07T13:07:19.940 に答える
1

クライアント側のJsonバインディングを使用している場合。チェック:dataSource->transport->parameterMapプロパティ。

そのような:

$(function () {
    $("#grid").kendoGrid({
          .....
         dataSource: {
          ....
          transport: {
               parameterMap: function (data, operation) {
                    if (operation != "read") {
                        .....
                        return result;
                    } else {
                        //data sample: {"take":10,"skip":0,"page":1,"pageSize":10}
                        //alert(JSON.stringify(data)); //Need to insert custom parameters into data object here for read method routing. so, reconstruct this object.
                        data.CustomParameter1 = "@Model.Parameter1"; // Got value from MVC view model.
                        data.CustomParameter2 = "@Model.Parameter2"; // Got value from MVC view model.
                        return JSON.stringify(data); // Here using post. MVC controller action need "HttpPost"
                }
          }
     }
 }

MVCコントローラー:

[HttpPost]
public ActionResult Read(int CustomParameter1, int CustomParameter2, int take, int skip, IEnumerable<Kendo.Mvc.Grid.CRUD.Models.Sort> sort, Kendo.Mvc.Grid.CRUD.Models.Filter filter)
{
         .....
}

法人化されたプロジェクトのサンプル:

http://www.telerik.com/support/code-library/grid-bound-to-asp-net-mvc-action-methods---crud-operations

于 2014-02-20T19:06:11.810 に答える