zoukankan      html  css  js  c++  java
  • KendoUI>Framework>Datasource>Overview

    KendoUI的DataSource绑定功能,既支持本地的JS对象数组,也支持远程的JSON,XML,JSONP。支持对数据的增删查改,以及对本地或服务端的数据排序,分页,筛选,分组,聚集。

    1.绑定本地JS对象数组

    var movies = [ {
          title: "Star Wars: A New Hope",
          year: 1977
       }, {
         title: "Star Wars: The Empire Strikes Back",
         year: 1980
       }, {
         title: "Star Wars: Return of the Jedi",
         year: 1983
       }
    ];
    var localDataSource = new kendo.data.DataSource({data: movies});

    2.绑定远程数据

    var dataSource = new kendo.data.DataSource({
        transport: {
            read: {
                // the remote service url
                url: "http://search.twitter.com/search.json",

                // JSONP is required for cross-domain AJAX
                dataType: "jsonp",

                // additional parameters sent to the remote service
                data: {
                    q: "html5"
                }
            }
        },
        // describe the result format
        schema: {
            // the data which the data source will be bound to is in the "results" field
            data: "results"
        }
    });

    3.给KendoUI绑定数据

    两种绑定方式,区别自己看。

    第一种:

    $("#chart").kendoChart({
        title: {
            text: "Employee Sales"
        },
        dataSource: new kendo.data.DataSource({
            data: [
            {
                employee: "Joe Smith",
                sales: 2000
            },
            {
                employee: "Jane Smith",
                sales: 2250
            },
            {
                employee: "Will Roberts",
                sales: 1550
            }]
        }),
        series: [{
            type: "line",
            field: "sales",
            name: "Sales in Units"
        }],
        categoryAxis: {
            field: "employee"
        }
    });

    第二种:

    var sharableDataSource = new kendo.data.DataSource({
        transport: {
            read: {
                url: "data-service.json",
                dataType: "json"
            }
        }
    });

    // Bind two UI widgets to same DataSource
    $("#chart").kendoChart({
        title: {
            text: "Employee Sales"
        },
        dataSource: sharableDataSource,
        series: [{
            field: "sales",
            name: "Sales in Units"
        }],
        categoryAxis: {
            field: "employee"
        }
    });

    $("#grid").kendoGrid({
        dataSource: sharableDataSource,
            columns: [
            {
                field: "employee",
                title: "Employee"
            },
            {
                field: "sales",
                title: "Sales",
                template: '#= kendo.toString(sales, "N0") #'
        }]
    });

    合乎自然而生生不息。。。
  • 相关阅读:
    python中map()函数
    Numpy学习—np.random.randn()、np.random.rand()和np.random.randint()
    列表、集合和字典推导式
    pandas iloc函数
    python -- 类中self到底有什么用?再续
    python apply()函数
    python 中关于self到底有什么用续
    python——类中的self到底有什么作用
    类初始化的参数可以是任何形式
    python高级(元类、自定义元类)
  • 原文地址:https://www.cnblogs.com/samwu/p/2432766.html
Copyright © 2011-2022 走看看