W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
DataSet最主要的功能就是為一份數(shù)據(jù)賦予一個(gè)名稱,使這份數(shù)據(jù)可以以配置的方式被其他控件引用,以便于建立綁定關(guān)系。 在定義DataSet時(shí),我們可以選擇以下兩種定義數(shù)據(jù)的方式之一。
直接把最終的數(shù)據(jù)交給DataSet。交給DataSet的數(shù)據(jù)的載體即可以是JSON+Array,也可以是Entity+EntityList。不過(guò)他們最終都會(huì)被包裝成Entity+EntityList
dataSet.setData({
"id":1,
"productName":"Chai1",
"categoryId":1,
"discontinued":true,
"quantityPerUnit":"10 boxes x 20 bags",
"reorderLevel":12,
"unitPrice":18,
"unitsInStock":39,
"unitsOnOrder":0
});
dataSet.setData([{
"id":1,
"productName":"Chai1",
"categoryId":1,
"discontinued":true,
"quantityPerUnit":"10 boxes x 20 bags",
"reorderLevel":12,
"unitPrice":18,
"unitsInStock":39,
"unitsOnOrder":0
},{
"id":2,
"productName":"Chang",
"categoryId":1,
"discontinued":true,
"quantityPerUnit":"24 - 12 oz bottles",
"reorderLevel":25,
"unitPrice":19,
"unitsInStock":17,
"unitsOnOrder":40
}]);
var entity = new dorado.Entity();
entity.fromJSON({
"id":1,
"productName":"Chai1",
"categoryId":1,
"discontinued":true,
"quantityPerUnit":"10 boxes x 20 bags",
"reorderLevel":12,
"unitPrice":18,
"unitsInStock":39,
"unitsOnOrder":0
});
dataSet.setData(entity);
var entityList = new dorado.EntityList();
entityList.fromJSON([{
"id":1,
"productName":"Chai1",
"categoryId":1,
"discontinued":true,
"quantityPerUnit":"10 boxes x 20 bags",
"reorderLevel":12,
"unitPrice":18,
"unitsInStock":39,
"unitsOnOrder":0
},{
"id":2,
"productName":"Chang",
"categoryId":1,
"discontinued":true,
"quantityPerUnit":"24 - 12 oz bottles",
"reorderLevel":25,
"unitPrice":19,
"unitsInStock":17,
"unitsOnOrder":40
}]);
dataSet.setData(entityList);
數(shù)據(jù)的提取方式告訴DataSet。這要利用DataProvider,我們接下來(lái)將會(huì)介紹這種對(duì)象。如果使用這種方式來(lái)定義DataSet中的數(shù)據(jù),那么DataSet將擁有數(shù)據(jù)懶裝載的特性,因此直到外界試圖通過(guò)DataSet提取數(shù)據(jù)時(shí),相應(yīng)的DataProvider才會(huì)被真正的激活。
dataSet.set("dataProvider", new dorado.AjaxDataProvider("data/phones.js"));
不過(guò)大部分場(chǎng)景我們還是直接在IDE設(shè)計(jì)器中定義DataProvider:
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: