W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
DataSet最主要的功能就是為一份數(shù)據(jù)賦予一個名稱,使這份數(shù)據(jù)可以以配置的方式被其他控件引用,以便于建立綁定關(guān)系。 在定義DataSet時,我們可以選擇以下兩種定義數(shù)據(jù)的方式之一。
直接把最終的數(shù)據(jù)交給DataSet。交給DataSet的數(shù)據(jù)的載體即可以是JSON+Array,也可以是Entity+EntityList。不過他們最終都會被包裝成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,我們接下來將會介紹這種對象。如果使用這種方式來定義DataSet中的數(shù)據(jù),那么DataSet將擁有數(shù)據(jù)懶裝載的特性,因此直到外界試圖通過DataSet提取數(shù)據(jù)時,相應(yīng)的DataProvider才會被真正的激活。
dataSet.set("dataProvider", new dorado.AjaxDataProvider("data/phones.js"));
不過大部分場景我們還是直接在IDE設(shè)計器中定義DataProvider:
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: