2

私はKendoGrid を持っていて、自分のController Action. トランスポート read.data を正常に使用できますが、parameterMap 機能の使用方法を学習しようとしています。

これが私が持っているものです:

<script>
$(document).ready(function () {
    var employeeNumber = @(ViewBag.EmployeeNumber);  //passed in from controller
    $("#ShoppingCartGrid").kendoGrid({

        dataSource: {
            dataType: "json",
            type:"GET",
            transport: {
                read: {
                    url:"../Requisitions/GetShoppingCartSummary/",
                    data: {
                        employeeNumber:employeeNumber  //passing param this way works
                    },
                }

            },
            schema: {  
 ...... //omitted for brevity
 </script>

これが機能しないものですが、ここに何を入れるべきかわかりません:

<script>
$(document).ready(function () {
    var employeeNumber = @(ViewBag.EmployeeNumber);
    $("#ShoppingCartGrid").kendoGrid({

        dataSource: {
            dataType: "json",
            type:"GET",
            transport: {
                read: {
                    url:"../Requisitions/GetShoppingCartSummary/"

                },
                parameterMap:function(options,operation){  // here is where I'm 
                    if (operation == "read") {            // running into issues- even  
                        return employeeNumber:"140412"; // hard coding param- no joy
                    }
                };

            },
            schema: {
  ...... //omitted for brevity
  </script>

解決策を何時間も探しましたが、この概念を十分に説明した投稿が見つからないようです。剣道のドキュメントへのリンクを送らないでください。そこにいたことを証明する精神的な傷があります。提案をありがとう。

4

2 に答える 2

1

トランスポート データ型は Json であるため、有効な Json パラメータを返す必要があります。Kendo は、parameterMap で提供された関数の結果を、URL で定義したメソッド名に追加します。

あなたの場合 - employeeNumber:"140412" は有効な Json ではありません。次の形式でパルマを提供する必要があります { paramname : value , otherparamname : value }。

JSON.stringify(o) を使用してパラメーターを正しく取得すると非常に便利です。

以下の parameterMap の構造は私にとってはうまくいきます:

parameterMap: function (o, operation) {
                        var output = null;
                        switch (operation) {
                            case "create":
                                output = '{ id: ' + JSON.stringify(o) + ' }';
                                break;
                            case "read":
                                output = '{ id: ' + globalVariable + ' ,  filters: ' + JSON.stringify(o) + '}';
                                break;
                            case "update":
                                output = '{ id:' + JSON.stringify(o) + '}';
                                break;
                            case "destroy":
                                output = '{ id : ' + o.param+ ' }';
                                break;
                        }
                        return output;
                    }

あなたのコメントに従ってもう少し詳細:

 parameterMap: function (o, operation) {
                        var output = null;
                        switch (operation) {
                             case "read":
                             var txt1 = $('#myTextBox1').val();
                             var txt2 = $('#myTextBox2').val();
                             var txt3 = $('#myTextBox3').val();
                             output = '{ textBoxValue1: ' + txt1  + ', textBoxValue2: ' + txt2 + ',textBoxValue3: ' + txt3 + '}';
                              break;
                            }
                            return output;
                        }

サーバー側のメソッド署名は次のようになります。

GetShoppingCartSummary(string textBoxValue1, string textBoxValue2, textBoxValue3);
于 2013-10-16T09:07:37.850 に答える
0

わかりました。return ステートメントを中括弧で囲む必要がありました。

これが私がその作品で終わったものです:

 <script>
$(document).ready(function () {
    var employeeNumber = @(ViewBag.EmployeeNumber);
     $("#ShoppingCartGrid").kendoGrid({
        dataSource: {
            dataType: "json",
            type:"GET",
            transport: {
                read: {
                    url:"../Requisitions/GetShoppingCartSummary/"

                    },
                parameterMap:function(options,operation){
                    if (operation == "read") {
                       return{
                            employeeNumber:employeeNumber
                          };
                     };
                   }  //parameterMap
                }, //transport

        schema: {
....Omitted for Brevity
</script>

オプションのパラメーターの配列を作成してから配列を返す方法など、他のオプションをいくつか見つけたいと思います。しかし、これは私が尋ねた質問に対する答えです。それが他の誰かに役立つことを願っています。

于 2013-10-16T00:19:39.193 に答える