JavaScript Recursive DataSource

A recursive data source is defined like a normal data source. The only difference with it is that some widgets, like the TreeView read it recursively for each level of child items, passing information about the parent item.

<script type="text/javascript">
var recursiveDS = new shield.RecursiveDataSource({
    remote: {
        read: function (params, success, error, extra) {
            if (!extra) {
                // if no extra params provided, it means
                // this is a read for the top level item
                $.ajax({
                    url: "/api/demo-component-demos"
                }).done(function (data) {
                    success(data, false, extra);
                }).fail(function () {
                    success([], false, extra);
                });
            }
            else {
                // there is a parent, so get its items from its
                // ChildrenUrl property
                $.ajax({
                    url: extra.parent.ChildrenUrl
                }).done(function (data) {
                    success(data, false, extra);
                }).fail(function () {
                    success([], false, extra);
                });
            }
        }
    }
});
</script>

To see it in action, refer to this example.