⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htmlstore.js

📁 这是一个ajax的例子大家好好的看看就是一个鱼眼的效果
💻 JS
📖 第 1 页 / 共 2 页
字号:
if(!dojo._hasResource["dojox.data.HtmlStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.dojo._hasResource["dojox.data.HtmlStore"] = true;dojo.provide("dojox.data.HtmlStore");dojo.require("dojox.data.dom");dojo.require("dojo.data.util.simpleFetch");dojo.require("dojo.data.util.filter");dojo.declare("dojox.data.HtmlStore", null, {	constructor: function(/*Object*/args){		//	summary:		//		Initializer for the HTML table store.  		//	description:		//		The HtmlStore can be created in one of two ways: a) by parsing an existing		//		table or list DOM node on the current page or b) by referencing an external url and giving		//		the id of the table or listin that page.  The remote url will be parsed as an html page.		//		//		The HTML table or list should be of the following form:		//		//		|	<table id="myTable">		//		|		<thead>		//		|			<tr>		//		|				<th>Attribute1</th>		//		|				<th>Attribute2</th>		//		|			</tr>		//		|		</thead>		//		|		<tbody>		//		|			<tr>		//		|				<td>Value1.1</td>		//		|				<td>Value1.2</td>		//		|			</tr>		//		|			<tr>		//		|				<td>Value2.1</td>		//		|				<td>Value2.2</td>		//		|			</tr>		//		|		</tbody>		//		|	</table>		//		// -or-		//		//		|	<ul id="myUnorderedList">		//		|		<li>Value.1</li>		//		|		<li>Value.2</li>		//		|	</ul>		//		// -or-		//		//		|	<ol id="myOrderedList">		//		|		<li>Value.1</li>		//		|		<li>Value.2</li>		//		|	</ol>		//		//	args:		//		An anonymous object to initialize properties.  It expects the following values:		//		dataId:	The id of the HTML table to use.		//		OR		//		url:	The url of the remote page to load		//		dataId:	The id of the table element in the remote page				if(args.url){			if(!args.dataId)				throw new Error("dojo.data.HtmlStore: Cannot instantiate using url without an id!");			this.url = args.url;			this.dataId = args.dataId;		}else{			if(args.dataId){				this._rootNode = dojo.byId(args.dataId);				this.dataId = this._rootNode.id;			}else{				this._rootNode = dojo.byId(this.dataId);			}			this._indexItems();		}	},	url: "",     // So the parser can instantiate the store via markup.	dataId: "", // So the parser can instantiate the store via markup.		_indexItems: function(){		this._getHeadings();		if (this._rootNode.rows){//tables			if(this._rootNode.tBodies && this._rootNode.tBodies.length > 0) {				this._rootNode = this._rootNode.tBodies[0];			}			var i;			for(i=0; i<this._rootNode.rows.length; i++){				this._rootNode.rows[i].store = this;				this._rootNode.rows[i]._ident = i+1;			}		}else{//lists			var c=1;			for(i=0; i<this._rootNode.childNodes.length; i++){				if(this._rootNode.childNodes[i].nodeType===1){					this._rootNode.childNodes[i].store = this;					this._rootNode.childNodes[i]._ident = c;					c++;				}			}		}	},	_getHeadings: function(){		//	summary:		//		Function to load the attribute names from the table header so that the 		//		attributes (cells in a row), can have a reasonable name.		//      For list items, returns single implicit heading, ["name"]		this._headings = [];		if(this._rootNode.tHead){			dojo.forEach(this._rootNode.tHead.rows[0].cells, dojo.hitch(this, function(th){				this._headings.push(dojox.data.dom.textContent(th));			}));		}else{			this._headings = ["name"];		}	},		_getAllItems: function(){		//	summary:		//		Function to return all rows in the table as an array of items.		var items = [];                var i;		if(this._rootNode.rows){//table			for(i=0; i<this._rootNode.rows.length; i++){				items.push(this._rootNode.rows[i]);			}		}else{ //list			for(i=0; i<this._rootNode.childNodes.length; i++){				if (this._rootNode.childNodes[i].nodeType===1){					items.push(this._rootNode.childNodes[i]);				}			}		}		return items; //array	},		_assertIsItem: function(/* item */ item){		//	summary:		//      This function tests whether the item passed in is indeed an item in the store.		//	item: 		//		The item to test for being contained by the store.		if(!this.isItem(item)){ 			throw new Error("dojo.data.HtmlStore: a function was passed an item argument that was not an item");		}	},	_assertIsAttribute: function(/* String */ attribute){		//	summary:		//      This function tests whether the item passed in is indeed a valid 'attribute' like type for the store.		//	attribute: 		//		The attribute to test for being contained by the store.		//		//	returns:		//		Returns the index (column) that the attribute resides in the row.		if(typeof attribute !== "string"){ 			throw new Error("dojo.data.HtmlStore: a function was passed an attribute argument that was not an attribute name string");			return -1;		}		return dojo.indexOf(this._headings, attribute); //int	},/***************************************     dojo.data.api.Read API***************************************/		getValue: function(	/* item */ item, 						/* attribute-name-string */ attribute, 						/* value? */ defaultValue){		//	summary: 		//      See dojo.data.api.Read.getValue()		var values = this.getValues(item, attribute);		return (values.length > 0)?values[0]:defaultValue; //Object || int || Boolean	},	getValues: function(/* item */ item, 						/* attribute-name-string */ attribute){		//	summary: 		//		See dojo.data.api.Read.getValues()		this._assertIsItem(item);		var index = this._assertIsAttribute(attribute);		if(index>-1){			if (item.cells){			  return [dojox.data.dom.textContent(item.cells[index])];			}else{//return Value for lists			    return [dojox.data.dom.textContent(item)];			}		}		return []; //Array	},	getAttributes: function(/* item */ item){		//	summary: 		//		See dojo.data.api.Read.getAttributes()		this._assertIsItem(item);		var attributes = [];		for(var i=0; i<this._headings.length; i++){			if(this.hasAttribute(item, this._headings[i]))				attributes.push(this._headings[i]);		}		return attributes; //Array	},	hasAttribute: function(	/* item */ item,							/* attribute-name-string */ attribute){		//	summary: 		//		See dojo.data.api.Read.hasAttribute()		return this.getValues(item, attribute).length > 0;	},	containsValue: function(/* item */ item, 							/* attribute-name-string */ attribute, 							/* anything */ value){		//	summary: 		//		See dojo.data.api.Read.containsValue()		var regexp = undefined;		if(typeof value === "string"){		   regexp = dojo.data.util.filter.patternToRegExp(value, false);		}		return this._containsValue(item, attribute, value, regexp); //boolean.	},	_containsValue: function(	/* item */ item, 								/* attribute-name-string */ attribute, 								/* anything */ value,								/* RegExp?*/ regexp){		//	summary: 		//		Internal function for looking at the values contained by the item.		//	description: 		//		Internal function for looking at the values contained by the item.  This 		//		function allows for denoting if the comparison should be case sensitive for		//		strings or not (for handling filtering cases where string case should not matter)		//			//	item:		//		The data item to examine for attribute values.		//	attribute:		//		The attribute to inspect.		//	value:			//		The value to match.		//	regexp:		//		Optional regular expression generated off value if value was of string type to handle wildcarding.		//		If present and attribute values are string, then it can be used for comparison instead of 'value'		var values = this.getValues(item, attribute);		for(var i = 0; i < values.length; ++i){			var possibleValue = values[i];			if(typeof possibleValue === "string" && regexp){				return (possibleValue.match(regexp) !== null);			}else{				//Non-string matching.				if(value === possibleValue){					return true; // Boolean				}			}		}		return false; // Boolean	},	isItem: function(/* anything */ something){		//	summary: 		//		See dojo.data.api.Read.isItem()		if(something && something.store && something.store === this){			return true; //boolean		}		return false; //boolean	},

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -