📄 htmlstore.js
字号:
isItemLoaded: function(/* anything */ something){ // summary: // See dojo.data.api.Read.isItemLoaded() return this.isItem(something); }, loadItem: function(/* Object */ keywordArgs){ // summary: // See dojo.data.api.Read.loadItem() this._assertIsItem(keywordArgs.item); }, _fetchItems: function(request, fetchHandler, errorHandler){ // summary: // Fetch items (XML elements) that match to a query // description: // If '_fetchUrl' is specified, it is used to load an XML document // with a query string. // Otherwise and if 'url' is specified, the XML document is // loaded and list XML elements that match to a query (set of element // names and their text attribute values that the items to contain). // A wildcard, "*" can be used to query values to match all // occurrences. // If '_rootItem' is specified, it is used to fetch items. // request: // A request object // fetchHandler: // A function to call for fetched items // errorHandler: // A function to call on error if(this._rootNode){ this._finishFetchItems(request, fetchHandler, errorHandler); }else{ if(!this.url){ this._rootNode = dojo.byId(this.dataId); }else{ var getArgs = { url: this.url, handleAs: "text" }; var self = this; var getHandler = dojo.xhrGet(getArgs); getHandler.addCallback(function(data){ var findNode = function(node, id){ if(node.id == id){ return node; //object } if(node.childNodes){ for(var i=0; i<node.childNodes.length; i++){ var returnNode = findNode(node.childNodes[i], id); if(returnNode){ return returnNode; //object } } } return null; //null } var d = document.createElement("div"); d.innerHTML = data; self._rootNode = findNode(d, self.dataId); self._indexItems(); self._finishFetchItems(request, fetchHandler, errorHandler); }); getHandler.addErrback(function(error){ errorHandler(error, request); }); } } }, _finishFetchItems: function(request, fetchHandler, errorHandler){ // summary: // Internal function for processing the passed in request and locating the requested items. var items = null; var arrayOfAllItems = this._getAllItems(); if(request.query){ var ignoreCase = request.queryOptions ? request.queryOptions.ignoreCase : false; items = []; //See if there are any string values that can be regexp parsed first to avoid multiple regexp gens on the //same value for each item examined. Much more efficient. var regexpList = {}; var key; var value; for(key in request.query){ value = request.query[key]+''; if(typeof value === "string"){ regexpList[key] = dojo.data.util.filter.patternToRegExp(value, ignoreCase); } } for(var i = 0; i < arrayOfAllItems.length; ++i){ var match = true; var candidateItem = arrayOfAllItems[i]; for(key in request.query){ value = request.query[key]+''; if (!this._containsValue(candidateItem, key, value, regexpList[key])){ match = false; } } if(match){ items.push(candidateItem); } } fetchHandler(items, request); }else{ // We want a copy to pass back in case the parent wishes to sort the array. We shouldn't allow resort // of the internal list so that multiple callers can get listsand sort without affecting each other. if(arrayOfAllItems.length> 0){ items = arrayOfAllItems.slice(0,arrayOfAllItems.length); } fetchHandler(items, request); } }, getFeatures: function(){ // summary: // See dojo.data.api.Read.getFeatures() return { 'dojo.data.api.Read': true, 'dojo.data.api.Identity': true }; }, close: function(/*dojo.data.api.Request || keywordArgs || null */ request){ // summary: // See dojo.data.api.Read.close() // nothing to do here! }, getLabel: function(/* item */ item){ // summary: // See dojo.data.api.Read.getLabel() if(this.isItem(item)){ if(item.cells){ return "Item #" + this.getIdentity(item); }else{ return this.getValue(item,"name"); } } return undefined; }, getLabelAttributes: function(/* item */ item){ // summary: // See dojo.data.api.Read.getLabelAttributes() if(item.cells){ return null; }else{ return ["name"]; } },/*************************************** dojo.data.api.Identity API***************************************/ getIdentity: function(/* item */ item){ // summary: // See dojo.data.api.Identity.getIdentity() this._assertIsItem(item); if(this.hasAttribute(item, "name")){ return this.getValue(item,"name"); }else{ return item._ident; } }, getIdentityAttributes: function(/* item */ item){ // summary: // See dojo.data.api.Identity.getIdentityAttributes() //Identity isn't taken from a public attribute. return null; }, fetchItemByIdentity: function(keywordArgs){ // summary: // See dojo.data.api.Identity.fetchItemByIdentity() var identity = keywordArgs.identity; var self = this; var item = null; var scope = null; if(!this._rootNode){ if(!this.url){ this._rootNode = dojo.byId(this.dataId); this._indexItems(); if(self._rootNode.rows){ //Table item = this._rootNode.rows[identity + 1]; }else{ //Lists for(var i = 0; i < self._rootNode.childNodes.length; i++){ if(self._rootNode.childNodes[i].nodeType === 1 && identity === dojox.data.dom.textContent(self._rootNode.childNodes[i])) { item = self._rootNode.childNodes[i]; } } } if(keywordArgs.onItem){ scope = keywordArgs.scope?keywordArgs.scope:dojo.global; keywordArgs.onItem.call(scope, item); } }else{ var getArgs = { url: this.url, handleAs: "text" }; var getHandler = dojo.xhrGet(getArgs); getHandler.addCallback(function(data){ var findNode = function(node, id){ if(node.id == id){ return node; //object } if(node.childNodes){ for(var i=0; i<node.childNodes.length; i++){ var returnNode = findNode(node.childNodes[i], id); if(returnNode){ return returnNode; //object } } } return null; //null } var d = document.createElement("div"); d.innerHTML = data; self._rootNode = findNode(d, self.dataId); self._indexItems(); if(self._rootNode.rows && identity <= self._rootNode.rows.length){ //Table item = self._rootNode.rows[identity-1]; }else{ //List for(var i = 0; i < self._rootNode.childNodes.length; i++){ if(self._rootNode.childNodes[i].nodeType === 1 && identity === dojox.data.dom.textContent(self._rootNode.childNodes[i])) { item = self._rootNode.childNodes[i]; break; } } } if(keywordArgs.onItem){ scope = keywordArgs.scope?keywordArgs.scope:dojo.global; keywordArgs.onItem.call(scope, item); } }); getHandler.addErrback(function(error){ if(keywordArgs.onError){ scope = keywordArgs.scope?keywordArgs.scope:dojo.global; keywordArgs.onError.call(scope, error); } }); } }else{ if(this._rootNode.rows[identity+1]){ item = this._rootNode.rows[identity+1]; if(keywordArgs.onItem){ scope = keywordArgs.scope?keywordArgs.scope:dojo.global; keywordArgs.onItem.call(scope, item); } } } }});dojo.extend(dojox.data.HtmlStore,dojo.data.util.simpleFetch);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -