簡體   English   中英

Kendo Grid-將數據打印到表格

[英]Kendo Grid - Print data to table

我正在嘗試使用kendo template功能在表中打印以下數據。 這是我通過ajax調用返回的數據:

{"Data":[{"CustomerID":1,"CustomerAltID":"IMI-001","CustomerName":"Henry Ford","Gender":"M"},{"CustomerID":2,"CustomerAltID":"IMI-002","CustomerName":"Bill Gates","Gender":"M"},{"CustomerID":3,"CustomerAltID":"IMI-003","CustomerName":"Muskan Shaik","Gender":"F"},{"CustomerID":4,"CustomerAltID":"IMI-004","CustomerName":"Richard Thrubi","Gender":"M"},{"CustomerID":5,"CustomerAltID":"IMI-005","CustomerName":"Emma Wattson","Gender":"F"},{"CustomerID":6,"CustomerAltID":"IMI-001","CustomerName":"Henry Ford","Gender":"M"},{"CustomerID":7,"CustomerAltID":"IMI-002","CustomerName":"Bill Gates","Gender":"M"},{"CustomerID":8,"CustomerAltID":"IMI-003","CustomerName":"Muskan Shaik","Gender":"F"},{"CustomerID":9,"CustomerAltID":"IMI-004","CustomerName":"Richard Thrubi","Gender":"M"},{"CustomerID":10,"CustomerAltID":"IMI-005","CustomerName":"Emma Wattson","Gender":"F"},{"CustomerID":11,"CustomerAltID":"IMI-001","CustomerName":"Henry Ford","Gender":"M"},{"CustomerID":12,"CustomerAltID":"IMI-002","CustomerName":"Bill Gates","Gender":"M"},{"CustomerID":13,"CustomerAltID":"IMI-003","CustomerName":"Muskan Shaik","Gender":"F"},{"CustomerID":14,"CustomerAltID":"IMI-004","CustomerName":"Richard Thrubi","Gender":"M"},{"CustomerID":15,"CustomerAltID":"IMI-005","CustomerName":"Emma Wattson","Gender":"F"}],"Total":15,"AggregateResults":null,"Errors":null}

這是我嘗試打印的方式:

<script id="javascriptTemplate" type="text/x-kendo-template">

    <table>
        <thead>
            <tr>
                <th>Customer ID</th>
                <th>ID</th>
                <th>Customer name</th>
                <th>Gender</th>
            </tr>
        </thead>
        <tbody>
            # for (var i=0; i < data.length; i++){ console.log(Object.keys(data[i]));#
            <tr>
                # var keys = Object.keys(data[i]) #
               # for (var j=1; j < keys.length; j++){ console.log(keys[j]); #
                <td>
                    #= data[i][keys[j]] #
                </td>
                # } #
            </tr>
            # } #
        </tbody>
    </table>

</script>

她的我的ajax電話:

<script>

    $.ajax(
        {
            type: 'POST',
            url: '/default1/KendoDataAjaxHandle/',
            dataType: 'json',
            success: function (result) {


                //Get the external template definition using a jQuery selector
                var template = kendo.template($("#javascriptTemplate").html());

                //console.log(result);
                var results = template(results); //Execute the template
                //console.log(results);
                $("#example").html(results); //Append the result

            }
        })

</script>

有人可以告訴我如何打印數據,因為我在表中沒有任何數據。

考慮您的數據

{"Data":[{"CustomerID":1,"CustomerAltID":"IMI-001","CustomerName":"Henry Ford","Gender":"M"}],"Total":15,"AggregateResults":null,"Errors":null}

問題:您是否未向模板分配正確的數據。

var results = template(results); //results are not the expected object

解決方案:您需要將results.Data傳遞到模板。 因此,使用此行。

var results = template(results.Data); //pass data to the template.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM