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

📄 itemfilewritestore.js

📁 ajax框架原吗,dojo目前很流行的,希望大家多多学习啊
💻 JS
📖 第 1 页 / 共 3 页
字号:
if(!dojo._hasResource["tests.data.ItemFileWriteStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.dojo._hasResource["tests.data.ItemFileWriteStore"] = true;dojo.provide("tests.data.ItemFileWriteStore");dojo.require("tests.data.readOnlyItemFileTestTemplates");dojo.require("dojo.data.ItemFileWriteStore");dojo.require("dojo.data.api.Read");dojo.require("dojo.data.api.Identity");dojo.require("dojo.data.api.Write");dojo.require("dojo.data.api.Notification");// First, make sure ItemFileWriteStore can still pass all the same unit tests // that we use for its superclass, ItemFileReadStore:tests.data.readOnlyItemFileTestTemplates.registerTestsForDatastore("dojo.data.ItemFileWriteStore");// Now run some tests that are specific to the write-access features:doh.register("tests.data.ItemFileWriteStore", 	[		function test_getFeatures(){			//	summary: 			//		Simple test of the getFeatures function of the store			//	description:			//		Simple test of the getFeatures function of the store			var store = new dojo.data.ItemFileWriteStore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));			var features = store.getFeatures(); 			// make sure we have the expected features:			doh.assertTrue(features["dojo.data.api.Read"] != null);			doh.assertTrue(features["dojo.data.api.Identity"] != null);			doh.assertTrue(features["dojo.data.api.Write"] != null);			doh.assertTrue(features["dojo.data.api.Notification"] != null);			doh.assertFalse(features["iggy"]);						// and only the expected features:			var count = 0;			for(var i in features){				doh.assertTrue((i === "dojo.data.api.Read" || 					i === "dojo.data.api.Identity" || 					i === "dojo.data.api.Write" || 					i === "dojo.data.api.Notification"));				count++;			}			doh.assertEqual(count, 4);		},		function testWriteAPI_setValue(){			//	summary: 			//		Simple test of the setValue API			//	description:			//		Simple test of the setValue API			var store = new dojo.data.ItemFileWriteStore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));			var deferred = new doh.Deferred();			function onComplete(items, request){				doh.assertEqual(1, items.length);				var item = items[0];				doh.assertTrue(store.containsValue(item, "capital", "Cairo"));								// FIXME:  				//    Okay, so this seems very odd.  Maybe I'm just being dense.				//    These tests works:				doh.assertEqual(store.isDirty(item), false);				doh.assertTrue(store.isDirty(item) == false);				//    But these seemingly equivalent tests will not work:				// doh.assertFalse(store.isDirty(item));				// doh.assertTrue(!(store.isDirty(item)));				//   				//    All of which seems especially weird, given that this *does* work:				doh.assertFalse(store.isDirty());												doh.assertTrue(store.isDirty(item) == false);				doh.assertTrue(!store.isDirty());				store.setValue(item, "capital", "New Cairo");				doh.assertTrue(store.isDirty(item));				doh.assertTrue(store.isDirty());				doh.assertEqual(store.getValue(item, "capital").toString(), "New Cairo");				deferred.callback(true);			}			function onError(error, request){				deferred.errback(error);			}			store.fetch({query:{name:"Egypt"}, onComplete: onComplete, onError: onError});			return deferred; //Object		},		function testWriteAPI_setValues(){			//	summary: 			//		Simple test of the setValues API			//	description:			//		Simple test of the setValues API			var store = new dojo.data.ItemFileWriteStore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));			var deferred = new doh.Deferred();			function onComplete(items, request){				doh.assertEqual(1, items.length);				var item = items[0];				doh.assertTrue(store.containsValue(item, "name", "Egypt"));				doh.assertTrue(store.isDirty(item) == false);				doh.assertTrue(!store.isDirty());				store.setValues(item, "name", ["Egypt 1", "Egypt 2"]);				doh.assertTrue(store.isDirty(item));				doh.assertTrue(store.isDirty());				var values = store.getValues(item, "name");				doh.assertTrue(values[0] == "Egypt 1");				doh.assertTrue(values[1] == "Egypt 2");				deferred.callback(true);			}			function onError(error, request){				deferred.errback(error);			}			store.fetch({query:{name:"Egypt"}, onComplete: onComplete, onError: onError});			return deferred; //Object		},		function testWriteAPI_unsetAttribute(){			//	summary: 			//		Simple test of the unsetAttribute API			//	description:			//		Simple test of the unsetAttribute API			var store = new dojo.data.ItemFileWriteStore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));			var deferred = new doh.Deferred();			function onComplete(items, request) {				doh.assertEqual(1, items.length);				var item = items[0];				doh.assertTrue(store.containsValue(item, "name", "Egypt"));				doh.assertTrue(store.isDirty(item) == false);				doh.assertTrue(!store.isDirty());				store.unsetAttribute(item, "name");				doh.assertTrue(store.isDirty(item));				doh.assertTrue(store.isDirty());				doh.assertTrue(!store.hasAttribute(item, "name"));				deferred.callback(true);			}			function onError(error, request) {				deferred.errback(error);			}			store.fetch({query:{name:"Egypt"}, onComplete: onComplete, onError: onError});			return deferred; //Object		},		function testWriteAPI_newItem(){			//	summary: 			//		Simple test of the newItem API			//	description:			//		Simple test of the newItem API			var store = new dojo.data.ItemFileWriteStore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));			var deferred = new doh.Deferred();			doh.assertTrue(!store.isDirty());			var onNewInvoked = false;			store.onNew = function(newItem, parentInfo){				doh.assertTrue(newItem !== null);				doh.assertTrue(parentInfo === null);				doh.assertTrue(store.isItem(newItem));				onNewInvoked = true;			};			var canada = store.newItem({name: "Canada", abbr:"ca", capital:"Ottawa"});			doh.assertTrue(onNewInvoked);						doh.assertTrue(store.isDirty(canada));			doh.assertTrue(store.isDirty());			doh.assertTrue(store.getValues(canada, "name") == "Canada");			function onComplete(items, request){				doh.assertEqual(1, items.length);				var item = items[0];				doh.assertTrue(store.containsValue(item, "name", "Canada"));				deferred.callback(true);			}			function onError(error, request){				deferred.errback(error);			}			store.fetch({query:{name:"Canada"}, onComplete: onComplete, onError: onError});			return deferred; //Object		},		function testWriteAPI_newItem_withParent(){			//	summary: 			//		Simple test of the newItem API with a parent assignment			//	description:			//		Simple test of the newItem API with a parent assignment			var store = new dojo.data.ItemFileWriteStore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));			var deferred = new doh.Deferred();			doh.assertTrue(!store.isDirty());			function onComplete(items, request){				doh.assertEqual(1, items.length);				var item = items[0];				doh.assertTrue(store.containsValue(item, "name", "Egypt"));				//Attach an onNew to validate we get expected values.				var onNewInvoked = false;				store.onNew = function(newItem, parentInfo){					doh.assertEqual(item, parentInfo.item);					doh.assertEqual("cities", parentInfo.attribute);					doh.assertTrue(parentInfo.oldValue === undefined);					doh.assertTrue(parentInfo.newValue === newItem);					onNewInvoked = true;				};                				//Attach an onSet and verify onSet is NOT called in this case.				store.onSet = function(item, attribute, oldValue, newValue){					doh.assertTrue(false);				};				//See if we can add in a new item representing the city of Cairo.				//This should also call the onNew set above....				var newItem = store.newItem({name: "Cairo", abbr: "Cairo"}, {parent: item, attribute: "cities"});				doh.assertTrue(onNewInvoked);				function onCompleteNewItemShallow(items, request){					doh.assertEqual(0, items.length);					function onCompleteNewItemDeep(items, request){						doh.assertEqual(1, items.length);						var item = items[0];						doh.assertEqual("Cairo", store.getValue(item, "name"));						deferred.callback(true);					}					//Do a deep search now, should find the new item of the city with name attribute Cairo.					store.fetch({query:{name:"Cairo"}, onComplete: onCompleteNewItemDeep, onError: onError, queryOptions: {deep:true}});				}				//Do a shallow search first, should find nothing.				store.fetch({query:{name:"Cairo"}, onComplete: onCompleteNewItemShallow, onError: onError});			}			function onError(error, request){				deferred.errback(error);			}			store.fetch({query:{name:"Egypt"}, onComplete: onComplete, onError: onError});			return deferred; //Object		},				function testWriteAPI_newItem_multiple_withParent(){			//	summary: 			//		Simple test of the newItem API with a parent assignment multiple times.			//	description:			//		Simple test of the newItem API with a parent assignment multiple times.			var store = new dojo.data.ItemFileWriteStore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));			var deferred = new doh.Deferred();						doh.assertTrue(!store.isDirty());						function onComplete(items, request){				doh.assertEqual(1, items.length);				var item = items[0];				doh.assertTrue(store.containsValue(item, "name", "Egypt"));				//Attach an onNew to validate we get expected values.				store.onNew = function(newItem, parentInfo){					doh.assertEqual(item, parentInfo.item);					doh.assertEqual("cities", parentInfo.attribute);										doh.assertTrue(parentInfo.oldValue === undefined);										doh.assertTrue(parentInfo.newValue === newItem);				};				//See if we can add in a new item representing the city of Cairo.				//This should also call the onNew set above....				var newItem1 = store.newItem({name: "Cairo", abbr: "Cairo"}, {parent: item, attribute: "cities"});								//Attach a new onNew to validate we get expected values.				store.onNew = function(newItem, parentInfo){					doh.assertEqual(item, parentInfo.item);					doh.assertEqual("cities", parentInfo.attribute);										console.log(parentInfo.oldValue);					doh.assertTrue(parentInfo.oldValue == newItem1);										doh.assertTrue(parentInfo.newValue[0] == newItem1);					doh.assertTrue(parentInfo.newValue[1] == newItem);				};				var newItem2 = store.newItem({name: "Banha", abbr: "Banha"}, {parent: item, attribute: "cities"});								//Attach a new onNew to validate we get expected values.				store.onNew = function(newItem, parentInfo){					doh.assertEqual(item, parentInfo.item);					doh.assertEqual("cities", parentInfo.attribute);										doh.assertTrue(parentInfo.oldValue[0] == newItem1);					doh.assertTrue(parentInfo.oldValue[1] == newItem2);										doh.assertTrue(parentInfo.newValue[0] == newItem1);					doh.assertTrue(parentInfo.newValue[1] == newItem2);					doh.assertTrue(parentInfo.newValue[2] == newItem);				};				var newItem3 = store.newItem({name: "Damanhur", abbr: "Damanhur"}, {parent: item, attribute: "cities"});				deferred.callback(true);			}			function onError(error, request){				deferred.errback(error);			}			store.fetch({query:{name:"Egypt"}, onComplete: onComplete, onError: onError});

⌨️ 快捷键说明

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