dojo0.9的store核心内容。最近研究了一些,也翻译了一些,贴出来和大家分享。dojo的更多内容可以上:
www.dojocn.cn 上查看。 一下内容是原创,转载请注明:
原文链接:https://www.f2er.com/dojo/291979.html
dojo.data 是什么?
dojo.data
DojoX
dojo.data
dojo.data
=========================================================================================================================
dojo.data 术语
dojo.data
dojo:datastore
db:cursor
dojo
db
dojo
db
dojo
db
dojo
db
dojo
db
dojo
db
dojo
db
internal data representation:
dojo
db
=============================================================================================================================
dojo.data 设计和编程接口
dojo.data.api.Read:
dojo.data.api.Write:
dojo.data.api.Identity:
dojo.data.api.Notification:
dojo.data.api.Schema
dojo.data.api.Attribution
dojo.data.api.Versioning
dojo.data.api.Derivation
---------------------------------------------------------------------------------
var store = new some.data.Store;
var items;
.......
//
//forvar i=0;i<items.length;i++{
var item=items[i];
console.log'For attribute 'foo' value was:['+store.getValueitem,'foo'+']';
}
----------------------------------------------------------------------------------
var value=item['foo'];
var value=item.foo;
var value=item.getValue'foo';
1item
2
3
=======================================================================================
The Read API
Dojo.data
l l n l n Iteml l l l l l l l itemitemlabelitemitem
1、var store = new some.Datastore;
var features = store.getFeatures;
forvar i in features{
console.log'Store supports feature: ' + i;
}
2、
var store = new some.Datastore;
ifstore.isItemsomeObject{
console.log'Object was an item.';
}else{
console.log'Object was NOT an item.';
}
3、
var store = new some.Datastore;
...
//Assume that someItem is an item we got from a load.
var attributes = store.getAttributessomeItem;
forvar i = 0; i < attributes.length; i++{
console.log'Item has attribute; ' + attributes[i];
}
4、
var store = new some.Datastore;
...
//Assume that someItem is an item we got from a load.
var attributes = store.getAttributessomeItem;
forvar i = 0; i < attributes.length; i++{
console.log'Item has attribute; ' + attributes[i];
}
5、
var store = new some.Datastore;
...
//Assume that someItem is an item we got from a load.
var label = store.getLabelsomeItem;
console.log'item has label: ' + label;
//
item
label
item
json
label:”name”
item
name
item
label
getLabel
name
getValueitem,”name”;
6
store
var pantryStore = new dojo.data.JsonItemStore{url: 'pantry_items.json' } ;
//Define the onComplete callback to write COMPLETED to the page when the fetch has finished returning items.
var done = functionitems,request{
document.appendChilddocument.createTextNode'COMPLETED';
}
//Define the callback that appends a textnode into the document each time an item is returned.
gotItem = functionitem,request {
document.appendChilddocument.createTextNodepantryStore.getValueitem,'name';
document.appendChilddocument.createElement'br';
}
//Define a simple error handler.
var gotError = functionerror,request{
alert'The request to the store Failed. ' +error;
}
//Invoke the search
pantryStore.fetch{onComplete: done,onItem: gotItem,onError: gotError};
//
onComplete
onItem
onComplete
items
null,
6、
var pantryStore = new dojo.data.JsonItemStore{url: 'pantry_items.json' } ;
var pepperItem = pantryStore.getItemByIdentity'pepper';
if pepperItem !== null{
alert'Pepper is in aisle ' + pantryStore.getValuepepperItem,'aisle';
}
//
json
, identifier: 'name'
item
name
7、
jsonItemStore.fetch{
queryOptions: {ignoreCase: true},//
query: { name: '*pepper*',aisle: 'Spices' },//name
aisle
onComplete:
...
};
8、
item
item
reference
getValues
9、
var store = new dojo.data.JsonItemStore{url: 'pantryStore.json' };
var pageSize = 10;
var request = null;
var outOfItems = false;
var onNext = function{
if!outOfItems{
request.start += pageSize;
store.fetchrequest;
}
};
var onPrevIoUs = function{
if request.start > 0{
request.start -= pageSize;
store.fetchrequest;
}
}
var itemsLoaded = functionitems,request{
if items.length < pageSize{
outOfItems = true;
}else{
outOfItems = false;
}
...
}
request = store.fetch{onComplete: itemsLoaded,start: 0; count: pageSize};
10、
var store = new dojo.data.JsonItemStore{url: 'pantryStore.json'};
var sortKeys = [
{attribute: 'aisle',descending: true},
{attribute: 'name',descending: false}
];
store.fetch{
sort: sortKeys;
onComplete:
...
};
//When onComplete is called,the array of items passed into it
//should be sorted according to the denoted sort array.
item
item