KendoMockjax

testing KendoUI with mock data

by mrlucmorin

HTML

<script src="https://raw.github.com/appendto/jquery-mockjax/master/jquery.mockjax.js"></script>
<script src="http://cdn.kendostatic.com/2012.1.322/js/kendo.all.min.js"></script>
<div id="container">
        <ul data-role="listview" data-template="ul-template" data-bind="source: theList">
        </ul>
</div>
<script id="ul-template" type="text/x-kendo-template">
<li>
    id: <span data-bind="text: ID"></span>
    name: <span data-bind="text: Name"></span>
</li>
</script>

JavaScript

var a = kendo.observable({
    theList: new kendo.data.DataSource({
        transport: {
            read: "/test/zaza",
            dataType: "json"
        },
        schema: {
            model: {
                id: "ID",
                fields: {
                    ID: {
                        editable: false,
                        nullable: false
                    },
                    Name: {
                        editable: true,
                        nullable: true
                    }
                }
            }
        }
    })
});

$.mockjax({
    url: "/test/zaza",
    responseTime: 750,
    responseText: [{ "ID": 0, "Name": "Larocque" }, { "ID": 1, "Name": "St-Louis" }, { "ID": 2, "Name": "Dorval" }, { "ID": 3, "Name": "St-Pierre" }]

});

kendo.bind($("#container"), a);