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

📄 opmlstore.js

📁 ajax框架原吗,dojo目前很流行的,希望大家多多学习啊
💻 JS
📖 第 1 页 / 共 3 页
字号:
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");			var opmlStore = new dojox.data.OpmlStore(args);			var d = new doh.Deferred();			function onComplete(items){				t.is(6, items.length);				t.assertTrue(opmlStore.isItem(items[0]));					var attributes = opmlStore.getAttributes(items[0]);				t.is(3, attributes.length);				for(var i = 0; i < attributes.length; i++){					t.assertTrue((attributes[i] === "text" || attributes[i] === "type" || attributes[i] === "children"));				}								d.callback(true);			}			//Get everything...			opmlStore.fetch({ onComplete: onComplete, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});			return d; //Object		},		function testReadAPI_getFeatures(t){			//	summary: 			//		Simple test of the getFeatures function of the store			//	description:			//		Simple test of the getFeatures function of the store			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");			var opmlStore = new dojox.data.OpmlStore(args);			var features = opmlStore.getFeatures(); 			var count = 0;			for(i in features){				t.assertTrue((i === "dojo.data.api.Read") || (i === "dojo.data.api.Identity"));				count++;			}			t.assertTrue(count === 2);		},		function testReadAPI_fetch_patternMatch0(t){			//	summary: 			//		Function to test pattern matching of everything starting with Capital A			//	description:			//		Function to test pattern matching of everything starting with Capital A			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");			var opmlStore = new dojox.data.OpmlStore(args);			var d = new doh.Deferred();			function completed(items, request){				t.is(3, items.length);				var valueArray = [ "Africa", "Asia", "Australia"];				t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", valueArray));				d.callback(true);			}						opmlStore.fetch({query: {text: "A*"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});			return d; //Object		},		function testReadAPI_fetch_patternMatch1(t){			//	summary: 			//		Function to test pattern matching of everything with America in it.			//	description:			//		Function to test pattern matching of everything with America in it.						var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");			var opmlStore = new dojox.data.OpmlStore(args);						var d = new doh.Deferred();			function completed(items, request){				t.assertTrue(items.length === 2);				var valueArray = [ "North America", "South America"];				t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", valueArray));				d.callback(true);			}						opmlStore.fetch({query: {text: "*America*"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});			return d; //Object		},		function testReadAPI_fetch_patternMatch2(t){			//	summary: 			//		Function to test exact pattern match			//	description:			//		Function to test exact pattern match						var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");			var opmlStore = new dojox.data.OpmlStore(args);						var d = new doh.Deferred();			function completed(items, request){				t.is(1, items.length);				t.assertTrue(opmlStore.getValue(items[0], "text") === "Europe");				d.callback(true);			}						opmlStore.fetch({query: {text: "Europe"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});			return d; //Object		},		function testReadAPI_fetch_patternMatch_caseInsensitive(t){			//	summary: 			//		Function to test exact pattern match with case insensitivity set.			//	description:			//		Function to test exact pattern match with case insensitivity set.						var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");			var opmlStore = new dojox.data.OpmlStore(args);						var d = new doh.Deferred();			function completed(items, request){				t.is(1, items.length);				t.assertTrue(opmlStore.getValue(items[0], "text") === "Asia");				d.callback(true);			}						opmlStore.fetch({query: {text: "asia"}, queryOptions: {ignoreCase: true}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});			return d; //Object		},		function testReadAPI_fetch_patternMatch_caseSensitive(t){			//	summary: 			//		Function to test exact pattern match with case sensitivity set.			//	description:			//		Function to test exact pattern match with case sensitivity set.						var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");			var opmlStore = new dojox.data.OpmlStore(args);						var d = new doh.Deferred();			function completed(items, request){				t.is(0, items.length);				d.callback(true);			}						opmlStore.fetch({query: {text: "ASIA"}, queryOptions: {ignoreCase: false}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});			return d; //Object		},		function testReadAPI_fetch_sortAlphabetic(t){			//	summary: 			//		Function to test sorting alphabetic ordering.			//	description:			//		Function to test sorting alphabetic ordering.					var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");			var opmlStore = new dojox.data.OpmlStore(args);						var d = new doh.Deferred();			function completed(items, request){				//Output should be in this order...				var orderedArray = [ "Africa", "Asia", "Australia", "Europe", "North America", "South America"];				t.is(6, items.length);				t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", orderedArray));				d.callback(true);			}						var sortAttributes = [{attribute: "text"}];			opmlStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});			return d; //Object		},		function testReadAPI_fetch_sortAlphabeticDescending(t){			//	summary: 			//		Function to test sorting alphabetic ordering in descending mode.			//	description:			//		Function to test sorting alphabetic ordering in descending mode.					var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");			var opmlStore = new dojox.data.OpmlStore(args);						var d = new doh.Deferred();			function completed(items, request){				//Output should be in this order...				var orderedArray = [ "South America", "North America", "Europe", "Australia", "Asia", "Africa"					];				t.is(6, items.length);				t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", orderedArray));				d.callback(true);			}						var sortAttributes = [{attribute: "text", descending: true}];			opmlStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});			return d; //Object		},		function testReadAPI_fetch_sortAlphabeticWithCount(t){			//	summary: 			//		Function to test sorting numerically in descending order, returning only a specified number of them.			//	description:			//		Function to test sorting numerically in descending order, returning only a specified number of them.					var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");			var opmlStore = new dojox.data.OpmlStore(args);						var d = new doh.Deferred();			function completed(items, request){				//Output should be in this order...				var orderedArray = [ "South America", "North America", "Europe", "Australia"					];				t.is(4, items.length);				t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", orderedArray));				d.callback(true);			}						var sortAttributes = [{attribute: "text", descending: true}];			opmlStore.fetch({sort: sortAttributes, 							count: 4,							onComplete: completed,							onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});			return d; //Object		},		function testReadAPI_functionConformance(t){			//	summary: 			//		Simple test read API conformance.  Checks to see all declared functions are actual functions on the instances.			//	description:			//		Simple test read API conformance.  Checks to see all declared functions are actual functions on the instances.			var testStore = new dojox.data.OpmlStore(dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"));			var readApi = new dojo.data.api.Read();			var passed = true;			for(i in readApi){				if(i.toString().charAt(0) !== '_')				{					var member = readApi[i];					//Check that all the 'Read' defined functions exist on the test store.					if(typeof member === "function"){						var testStoreMember = testStore[i];						if(!(typeof testStoreMember === "function")){							passed = false;							break;						}					}				}			}			t.assertTrue(passed);		},		function testIdentityAPI_fetchItemByIdentity(t){			//	summary: 			//		Simple test of the fetchItemByIdentity function of the store.			//	description:			//		Simple test of the fetchItemByIdentity function of the store.						var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");			var opmlStore = new dojox.data.OpmlStore(args);						var d = new doh.Deferred();			function onItem(item){				t.assertTrue(item !== null);				d.callback(true);				}            opmlStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});			return d;		},		function testIdentityAPI_fetchItemByIdentity_bad1(t){			//	summary: 			//		Simple test of the fetchItemByIdentity function of the store.			//	description:			//		Simple test of the fetchItemByIdentity function of the store.						var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");			var opmlStore = new dojox.data.OpmlStore(args);						var d = new doh.Deferred();			function onItem(item){				t.assertTrue(item === null);				d.callback(true);				}            opmlStore.fetchItemByIdentity({identity: "200", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});			return d;		},		function testIdentityAPI_fetchItemByIdentity_bad2(t){			//	summary: 			//		Simple test of the fetchItemByIdentity function of the store.			//	description:			//		Simple test of the fetchItemByIdentity function of the store.						var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");			var opmlStore = new dojox.data.OpmlStore(args);			var d = new doh.Deferred();			function onItem(item){				t.assertTrue(item === null);				d.callback(true);				}            opmlStore.fetchItemByIdentity({identity: "-1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});			return d;		},		function testIdentityAPI_fetchItemByIdentity_bad3(t){			//	summary: 			//		Simple test of the fetchItemByIdentity function of the store.			//	description:			//		Simple test of the fetchItemByIdentity function of the store.						var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");			var opmlStore = new dojox.data.OpmlStore(args);			var d = new doh.Deferred();			function onItem(item){				t.assertTrue(item === null);				d.callback(true);				}            opmlStore.fetchItemByIdentity({identity: "999999", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});			return d;		},		function testIdentityAPI_getIdentity(t){			//	summary: 			//		Simple test of the fetchItemByIdentity function of the store.			//	description:			//		Simple test of the fetchItemByIdentity function of the store.						var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");			var opmlStore = new dojox.data.OpmlStore(args);						var d = new doh.Deferred();			function completed(items, request){				var passed = true;				for(var i = 0; i < items.length; i++){					console.log("Identity is: " + opmlStore.getIdentity(items[i]) + " count is : "+ i);					if(!(opmlStore.getIdentity(items[i]) == i)){						passed=false;						break;					}				}				t.assertTrue(passed);				d.callback(true);			}						//Get everything...			opmlStore.fetch({ onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d), queryOptions: {deep: true}});			return d; //Object		},		function testIdentityAPI_functionConformance(t){			//	summary: 			//		Simple test identity API conformance.  Checks to see all declared functions are actual functions on the instances.			//	description:			//		Simple test identity API conformance.  Checks to see all declared functions are actual functions on the instances.			var testStore = new dojox.data.OpmlStore(dojox.data.tests.stores.CsvStore.getDatasource("stores/geography.xml"));			var identityApi = new dojo.data.api.Identity();			var passed = true;			for(i in identityApi){				if(i.toString().charAt(0) !== '_')				{					var member = identityApi[i];					//Check that all the 'Read' defined functions exist on the test store.					if(typeof member === "function"){						console.log("Looking at function: [" + i + "]");						var testStoreMember = testStore[i];						if(!(typeof testStoreMember === "function")){							passed = false;							break;						}					}				}			}			t.assertTrue(passed);		}	]);}

⌨️ 快捷键说明

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