8051510e8f6a3afc62a1dbd623d13f9f68460aad.svn-base 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <!--
  2. This file demonstrates how the dojox.wire code can be used to do declarative
  3. wiring of events on one item to trigger event on other items. It also shows
  4. how you can use the Transfer object to morph data values from one format to
  5. another. In this specific case, it maps the values from a dojo.data Datastore
  6. item into values stored in a JavaScript Array, which is the format required for
  7. the addRow method of the demonstration TableContainer.
  8. Note that this demo expects dojo, digit, and dojox to all be peers in the same directory
  9. in order for it to execute.
  10. -->
  11. <html>
  12. <head>
  13. <title>Sample Declarative Data Binding using ColumnWire</title>
  14. <style type="text/css">
  15. @import "../../../../dijit/themes/tundra/tundra.css";
  16. @import "../../../../dojo/resources/dojo.css";
  17. @import "../../../../dijit/tests/css/dijitTests.css";
  18. @import "../TableContainer.css";
  19. </style>
  20. <script type="text/javascript" src="../../../../dojo/dojo.js" djConfig="isDebug: true, parseOnLoad: true"></script>
  21. <script type="text/javascript">
  22. dojo.require("dojo.parser");
  23. dojo.require("dojox.wire.ml.Invocation");
  24. dojo.require("dojox.wire.ml.DataStore");
  25. dojo.require("dojox.wire.ml.Transfer");
  26. dojo.require("dijit._Widget");
  27. dojo.require("dijit._Templated");
  28. dojo.require("dojo.data.ItemFileReadStore");
  29. dojo.require("dojox.wire");
  30. dojo.require("dojox.wire.demos.TableContainer");
  31. //Toplevel JS Object to contain a few basics for us, such as the request to pass to the store and a stub onItem function
  32. // to trap on for triggering other events.
  33. dataHolder = {
  34. //Simple object definition to get all items and sort it by the attribute 'type'.
  35. request: {onItem: function(item){}, sort: [{attribute: "type"}]},
  36. //Spot to store off data values as they're generated by the declarative binding.
  37. result: null
  38. };
  39. </script>
  40. </head>
  41. <body class="tundra">
  42. <!--
  43. The store that is queried in this demo
  44. -->
  45. <div dojoType="dojo.data.ItemFileReadStore"
  46. jsId="DataStore1"
  47. url="countries.json">
  48. </div>
  49. <!--
  50. On load of the page, invoke the fetch method of the object 'DataStore1',
  51. get its parameters from the JS object 'sample.request
  52. -->
  53. <div dojoType="dojox.wire.ml.Invocation"
  54. triggerEvent="onLoad"
  55. object="DataStore1" method="fetch" parameters="dataHolder.request"></div>
  56. <!--
  57. Simple container widget for creating a 'table from rows defined by an array
  58. -->
  59. <div dojoType="dojox.wire.demos.TableContainer" jsId="r1" headers="Name,Location Type"></div>
  60. <!--
  61. On the call of the onItem function of 'dataHolder', trigger a binding/mapping of the
  62. item's attribute 'name' and 'type' attributes to specific columns in an array. Note here that since
  63. sourceStore is set, it treats the arguments as items from that store and accesses the attributes
  64. appropriately. In this case 'name' becomes array entry 0, type, array entry 1, and so on.
  65. Then take the result of the data mapping and pass it into the invoke of the addRow function on the
  66. TableContainer widget.
  67. -->
  68. <div dojoType="dojox.wire.ml.Action"
  69. trigger="dataHolder.request" triggerEvent="onItem">
  70. <div dojoType="dojox.wire.ml.Transfer"
  71. source="arguments[0]" sourceStore="DataStore1"
  72. target="dataHolder.result">
  73. <div dojoType="dojox.wire.ml.ColumnWire" attribute="name"></div>
  74. <div dojoType="dojox.wire.ml.ColumnWire" attribute="type"></div>
  75. </div>
  76. <div dojoType="dojox.wire.ml.Invocation"
  77. object="r1" method="addRow" parameters='dataHolder.result'>
  78. </div>
  79. </div>
  80. </body>
  81. </html>