原創(chuàng)|使用教程|編輯:龔雪|2016-10-31 09:36:45.000|閱讀 2514 次
概述:Kendo的數據源支持本地數據源(JavaScript對象數組),或者遠程數據源(XML, JSON, JSONP),支持CRUD操作(創(chuàng)建,讀取,更新和刪除操作),并支持排序,分頁,過濾,分組和集合等。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Kendo的數據源支持本地數據源(JavaScript對象數組),或者遠程數據源(XML, JSON, JSONP),支持CRUD操作(創(chuàng)建,讀取,更新和刪除操作),并支持排序,分頁,過濾,分組和集合等。
下面創(chuàng)建一個本地數據源。
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});
創(chuàng)建一個遠程數據源 (Twitter)
var dataSource = new kendo.data.DataSource({
transport: {
read: {
// the remote service url
url: “//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”
}
});
Kendo UI組件很多都支持數據綁定 ,UI組件綁定的數據源可以在配置UI組件時設置,或是多個UI組件共享同一個數據源。創(chuàng)建UI組件時設置DataSource屬性:
$(“#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″) #’
}]
});
這個例子使用了模板 template,模板的用法參見后面的文章。
本站文章除注明轉載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn
文章轉載自:慧都控件網