1

メソッドからデータ (IN Json 形式) を読み取る KendoUI DataSource がページにあり、スクリプトは次のとおりです。

 <script id="template" type="text/x-kendo-template">
            <tr>
                <td>#= ID #</td>
                <td>#= TITLE #</td>
                <td>#= DESC #</td>

            </tr>
        </script>

            <script>
                $(document).ready(function () {
                    // create a template using the above definition
                    var template = kendo.template($("#template").html());

                    var datas = function() {

                        var objects = [];
                        $.ajax({
                            type: "POST",
                            url: "./WebForm1.aspx/GetNoti",
                            data: {},
                            async: false,
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            success:
                                function(response) {

                                    for (var i = 0; i < response.d.length; i++) {

                                        objects.push({ 'ID': response.d[i].ID, 'TITLE': response.d[i].TITLE, 'DESC': response.d[i].DESC });

                                    }
                                },

                        });
                        return objects;
                    };                       

                    var dataSource = new kendo.data.DataSource({
                        data: datas(),
                        change: function () { // subscribe to the CHANGE event of the data source
                            $("#movies tbody").html(kendo.render(template, this.view())); // populate the table
                        }
                    });

                    dataSource.read();
                });
        </script>

そして、データベースに新しく追加された新しいデータを提供し、それを KendoUI Datasource に表示するメソッドを呼び出す setInterval 関数による別のスクリプトが必要です。

私はこのように前にそれを試しました:

 <script>
    $(document).ready(function () {
        $("#go").click(function () {
            setInterval(function () {
                var dataSource= new kendo.data.DataSource({
                    data=function ()
                {

                    $.ajax({
                        type: "POST",
                        url: "WebForm1.aspx/GetNewNoti",
                        data: '{}',
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function(response) {

                            for (var i = 0; i < response.d.length; i++) {
                                dataSource.add({ 'ID': response.d[i].ID, 'TITLE': response.d[i].TITLE, 'DESC': response.d[i].DESC });
                            };
                        },
                    });

                    },
           });

            }, 8000);
        });
    });

</script>

誰でも私を助けることができますか?

編集:私は次のように2番目のスクリプトを編集します:

$("#go").click(function () {
                  setInterval(function () {test2(); }, 8000);
                    });

テスト 2 :

function test2() {

                  var dataSource2 = new kendo.data.DataSource({
                       data: p(),
                       change: function () {
                       $("#movies tbody").html(kendo.render(template, this.view())); }

                      });
                   dataSource2.read();

                    }

そして、次のような p() があります。

var p = function test() {
             var objects = [];
                 $.ajax({
                     type: "POST",
                     url: "./WebForm1.aspx/GetUnCheckNotification",
                     data: {},
                     async: false,
                     contentType: "application/json; charset=utf-8",
                     dataType: "json"
                     success: function(response) {
                                 for (var i = 0; i < response.d.length; i++) {
                                       objects.push({ 'ID': response.d[i].ID, 'TITLE':response.d[i].TITLE, 'DESC': response.d[i].DESC });

                                    }
                                },
                        });
                        return objects;

                    };

この方法で、(最初のスクリプトで) dataSource2 を datasource に追加する方法が必要ですが、方法はありますか?

4

1 に答える 1