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") #'
        }]
    });

    合乎自然而生生不息。。。
  • 相关阅读:
    第2章 面向对象的设计原则(SOLID):5_迪米特法则
    第2章 面向对象的设计原则(SOLID):4_接口隔离原则(ISP)
    第2章 面向对象的设计原则(SOLID):3_依赖倒置原则(DIP)
    第2章 面向对象的设计原则(SOLID):1_单一职责原则(SRP)
    第1章 UML基础:类的关系
    将DHT11移植到Linux系统上(转)
    Linux下用文件IO的方式操作GPIO(/sys/class/gpio)(转)
    asm335x系列adc和触摸屏驱动(转)
    (原创)AP6212蓝牙模块在am335x控制板上的应用
    Am335x 下GPIO控制实例-驱动程序(转)
  • 原文地址:https://www.cnblogs.com/samwu/p/2432766.html
Copyright © 2011-2022 走看看