?? opmlstore.js
字號:
var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"); var opmlStore = new dojox.data.OpmlStore(args); var d = new doh.Deferred(); function dumpFirstFetch(items, request){ t.is(5, items.length); request.start = 3; request.count = 1; request.onComplete = dumpSecondFetch; opmlStore.fetch(request); } function dumpSecondFetch(items, request){ t.is(1, items.length); request.start = 0; request.count = 5; request.onComplete = dumpThirdFetch; opmlStore.fetch(request); } function dumpThirdFetch(items, request){ t.is(5, items.length); request.start = 2; request.count = 20; request.onComplete = dumpFourthFetch; opmlStore.fetch(request); } function dumpFourthFetch(items, request){ t.is(4, items.length); request.start = 9; request.count = 100; request.onComplete = dumpFifthFetch; opmlStore.fetch(request); } function dumpFifthFetch(items, request){ t.is(0, items.length); request.start = 2; request.count = 20; request.onComplete = dumpSixthFetch; opmlStore.fetch(request); } function dumpSixthFetch(items, request){ t.is(4, items.length); d.callback(true); } function completed(items, request){ t.is(6, items.length); request.start = 1; request.count = 5; request.onComplete = dumpFirstFetch; opmlStore.fetch(request); } opmlStore.fetch({onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)}); return d; //Object }, function testReadAPI_getLabel(t){ // summary: // Simple test of the getLabel function against a store set that has a label defined. // description: // Simple test of the getLabel function against a store set that has a label defined. 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, request){ t.assertEqual(items.length, 1); var label = opmlStore.getLabel(items[0]); t.assertTrue(label !== null); t.assertEqual("Asia", label); d.callback(true); } opmlStore.fetch({ query: {text: "Asia"}, onComplete: onComplete, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d) }); return d; }, function testReadAPI_getLabelAttributes(t){ // summary: // Simple test of the getLabelAttributes function against a store set that has a label defined. // description: // Simple test of the getLabelAttributes function against a store set that has a label defined. 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, request){ t.assertEqual(items.length, 1); var labelList = opmlStore.getLabelAttributes(items[0]); t.assertTrue(dojo.isArray(labelList)); t.assertEqual("text", labelList[0]); d.callback(true); } opmlStore.fetch({ query: {text: "Asia"}, onComplete: onComplete, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d) }); return d; }, function testReadAPI_getLabel_nondefault(t){ // summary: // Simple test of the getLabel function against a store set that has a label defined. // description: // Simple test of the getLabel function against a store set that has a label defined. var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography_withspeciallabel.xml"); args.label="label"; var opmlStore = new dojox.data.OpmlStore(args); var d = new doh.Deferred(); function onComplete(items, request){ t.assertEqual(items.length, 1); var label = opmlStore.getLabel(items[0]); t.assertTrue(label !== null); t.assertEqual("Continent/Asia", label); d.callback(true); } opmlStore.fetch({ query: {text: "Asia"}, onComplete: onComplete, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d) }); return d; }, function testReadAPI_getLabelAttributes_nondefault(t){ // summary: // Simple test of the getLabelAttributes function against a store set that has a label defined. // description: // Simple test of the getLabelAttributes function against a store set that has a label defined. var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography_withspeciallabel.xml"); args.label="label"; var opmlStore = new dojox.data.OpmlStore(args); var d = new doh.Deferred(); function onComplete(items, request){ t.assertEqual(items.length, 1); var labelList = opmlStore.getLabelAttributes(items[0]); t.assertTrue(dojo.isArray(labelList)); t.assertEqual("label", labelList[0]); d.callback(true); } opmlStore.fetch({ query: {text: "Asia"}, onComplete: onComplete, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d) }); return d; }, function testReadAPI_getValue(t){ // summary: // Simple test of the getValue function of the store. // description: // Simple test of the getValue 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 completedAll(items){ t.is(6, items.length); t.is("Africa", opmlStore.getValue(items[0],"text")); t.is("Asia", opmlStore.getValue(items[1],"text")); t.is("Australia", opmlStore.getValue(items[2],"text")); t.is("Europe", opmlStore.getValue(items[3],"text")); t.is("North America", opmlStore.getValue(items[4],"text")); t.is("South America", opmlStore.getValue(items[5],"text")); t.is("continent", opmlStore.getValue(items[1],"type")); t.is("21 million", opmlStore.getValue(items[2],"population")); var firstChild = opmlStore.getValue(items[4],"children"); t.assertTrue(opmlStore.isItem(firstChild)); t.is("Mexico", opmlStore.getValue(firstChild,"text")); t.is("country", opmlStore.getValue(firstChild,"type")); t.is("108 million", opmlStore.getValue(firstChild,"population")); t.is("1,972,550 sq km", opmlStore.getValue(firstChild,"area")); firstChild = opmlStore.getValue(firstChild,"children"); t.assertTrue(opmlStore.isItem(firstChild)); t.is("Mexico City", opmlStore.getValue(firstChild,"text")); t.is("city", opmlStore.getValue(firstChild,"type")); t.is("19 million", opmlStore.getValue(firstChild,"population")); t.is("-6 UTC", opmlStore.getValue(firstChild,"timezone")); d.callback(true); } //Get everything... opmlStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)}); return d; //Object }, function testReadAPI_getValues(t){ // summary: // Simple test of the getValues function of the store. // description: // Simple test of the getValues 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){ t.is(1, items.length); var children = opmlStore.getValues(items[0],"children"); t.is(3, children.length); for(var i=0; i<children.length; i++){ t.assertTrue(opmlStore.isItem(children[i])); } t.is("Mexico", opmlStore.getValues(children[0],"text")[0]); t.is("country", opmlStore.getValues(children[0],"type")[0]); t.is("108 million", opmlStore.getValues(children[0],"population")[0]); t.is("1,972,550 sq km", opmlStore.getValues(children[0],"area")[0]); t.is("Canada", opmlStore.getValues(children[1],"text")[0]); t.is("country", opmlStore.getValues(children[1],"type")[0]); children = opmlStore.getValues(children[1],"children"); t.is(2, children.length); for(var i=0; i<children.length; i++){ t.assertTrue(opmlStore.isItem(children[i])); } t.is("Ottawa", opmlStore.getValues(children[0],"text")[0]); t.is("Toronto", opmlStore.getValues(children[1],"text")[0]); d.callback(true); } //Get one item... opmlStore.fetch({ query: {text: "North America"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)}); return d; //Object }, function testReadAPI_isItem(t){ // summary: // Simple test of the isItem function of the store // description: // Simple test of the isItem 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 completedAll(items){ t.is(6, items.length); for(var i=0; i<6; i++){ t.assertTrue(opmlStore.isItem(items[i])); } t.assertTrue(!opmlStore.isItem({})); t.assertTrue(!opmlStore.isItem({ item: "not an item" })); t.assertTrue(!opmlStore.isItem("not an item")); t.assertTrue(!opmlStore.isItem(["not an item"])); d.callback(true); } //Get everything... opmlStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)}); return d; //Object }, function testReadAPI_hasAttribute(t){ // summary: // Simple test of the hasAttribute function of the store // description: // Simple test of the hasAttribute 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 onComplete(items){ t.is(1, items.length); t.assertTrue(items[0] !== null); t.assertTrue(opmlStore.hasAttribute(items[0], "text")); t.assertTrue(opmlStore.hasAttribute(items[0], "type")); t.assertTrue(!opmlStore.hasAttribute(items[0], "population")); t.assertTrue(!opmlStore.hasAttribute(items[0], "Nothing")); t.assertTrue(!opmlStore.hasAttribute(items[0], "Text")); //Test that null attributes throw an exception var passed = false; try{ opmlStore.hasAttribute(items[0], null); }catch (e){ passed = true; } t.assertTrue(passed); d.callback(true); } //Get one item... opmlStore.fetch({ query: {text: "Asia"}, onComplete: onComplete, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d) }); return d; //Object }, function testReadAPI_containsValue(t){ // summary: // Simple test of the containsValue function of the store // description: // Simple test of the containsValue 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 onComplete(items){ t.is(1, items.length); t.assertTrue(items[0] !== null); t.assertTrue(opmlStore.containsValue(items[0], "text", "North America")); t.assertTrue(opmlStore.containsValue(items[0], "type", "continent")); t.assertTrue(!opmlStore.containsValue(items[0], "text", "America")); t.assertTrue(!opmlStore.containsValue(items[0], "Type", "continent")); t.assertTrue(!opmlStore.containsValue(items[0], "text", null)); var children = opmlStore.getValues(items[0], "children"); t.assertTrue(opmlStore.containsValue(items[0], "children", children[0])); t.assertTrue(opmlStore.containsValue(items[0], "children", children[1])); t.assertTrue(opmlStore.containsValue(items[0], "children", children[2])); //Test that null attributes throw an exception var passed = false; try{ opmlStore.containsValue(items[0], null, "foo"); }catch (e){ passed = true; } t.assertTrue(passed); d.callback(true); } //Get one item... opmlStore.fetch({ query: {text: "North America"}, onComplete: onComplete, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d) }); return d; //Object }, function testReadAPI_getAttributes(t){ // summary: // Simple test of the getAttributes function of the store // description: // Simple test of the getAttributes function of the store
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -