原創(chuàng)|使用教程|編輯:郝浩|2013-03-27 14:11:30.000|閱讀 819 次
概述:DXTREME ENTERPRISE中的Store公開了幾種方法來執(zhí)行與持久性存儲相關的基本功能。本文將通過代碼來詳細介紹。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
DXTREME ENTERPRISE中的Store公開了幾種方法來執(zhí)行與持久性存儲相關的基本功能。下面來詳細看一下:
Insert
創(chuàng)建一個作為方法參數(shù)到對象。
// create a new person // with the name property set to 'Josh' and age property set to 29 var newPerson = { name: "Josh", age: 29 }; myPersonStore.insert(newPerson).done(function (createdPerson, personKey) { // the insert callback receives two arguments - a created object and its key });
Load
從存儲區(qū)中加載的對象,注意此方法通過選項參支持高級查詢。
myPersonStore.load().done(function (result) { // the load callback receives a single argument - an array of the retrieved objects });
Update
按第二個參數(shù)傳遞的數(shù)據(jù),用指定的鍵修改對象。
// change the name of the person whose key is 15 to 'James' myPersonStore.update(15, { name: "James" }).done(function (personKey, modifiedPerson) { // the update callback receives two arguments - an updated object's key and the object itself });
Remove
刪除指定的鍵的對象。
// remove the person whose key is 67 myPersonStore.remove(67).done(function (personKey) { // the remove callback receives a single argument - the key of a deleted object });
示例
下面的代碼段是一個完整的例子演示了所有的基本存儲操作。首先,聲明一個空的存儲,然后按照順序執(zhí)行所有的操作。一個對象插入到store后,然后更新、加載、最后移除。
var personStore = new DevExpress.data.ArrayStore({ key: "id", data: [] }); personStore.insert({ name: "Josh", age: 29 }).done(onInsert); function onInsert(createdPerson, personKey) { alert("created an object with the '" + personKey + "' key"); personStore.update(personKey, { name: "James" }).done(onUpdate); }; function onUpdate(personKey, modifiedPerson) { alert("changed the object's name to '" + modifiedPerson.name + "'"); personStore.load().done(onLoad); }; function onLoad(result) { alert("loaded " + result.length + "object(s)"); personStore.remove(result[0].id).done(onRemove); }; function onRemove(personKey) { alert("removed an object with the '" + personKey + "' key"); };
標簽:
本站文章除注明轉載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件