[Dojo-interest] Accessing a declaratively defined store

Kitson Kelly kitson.kelly at asseverate.co.uk
Wed May 30 14:46:13 EDT 2012


The attribute "data-dojo-id" will cause the parser to do is create a global
variable with the value of that attribute, so in order to access the store,
just use what you have there:

projectStore.add(newEntry);


Is that not working?

BTW, your declarative script for the button isn't so good.  Try the
following:

<script type="dojo/on" data-dojo-event="click">
  // ... handler...
</script>




On 30 May 2012 18:53, Samuel Gilbert <samuel.gilbert at ec.gc.ca> wrote:

> Hello,
>
>  I'm pretty much a Dojo noob, and I have a question regarding how to
> access a
> data store that was declaratively defined.
>
>  What I have is a FilteringSelect for which I created a JSON/REST data
> store.
> The fetching works correctly and the items get displayed in the
> FilteringSelect.  However, I also have a button which bring up a dialog to
> add
> a new item in the store.  The actual question is : how do I access the
> store
> that I defined declaratively in the event handler of the button?
>
>  I tried dijit.byId() and dojo.query(), but since the store is neither a
> DOM
> node nor a dijit widget, it, as expected, didn't work.
>
> Here is an example illustrating my problem :
>
> <div data-dojo-type="dojo.store.JsonRest"
>         data-dojo-id="projectStore"
>         data-dojo-props="target: '/db/project'"></div>
> <input data-dojo-type="dijit.form.FilteringSelect"
>         data-dojo-props="store:projectStore, searchAttr:'name',
> popercase:true"
>         name="project"
>         id="projectInput">
>
> <button data-dojo-type="dijit.form.Button" type="button">Add a new project
> <script type="dojo/method" data-dojo-event="onClick" data-dojo-args="evt">
>               function entry(newName, newDesc) {
>                  this.id = -1;
>                  this.name = newName;
>                  this.newDesc = newDesc;
>               }
>               var projectName = dijit.byId("projectName");
>               var projectDescription = dijit.byId("projectDescription");
>               var newEntry = new entry(projectName.value,
> projectDescription.value);
>               // How do I get an handle on the projectStore here??
>               projectStore.add(newEntry);
> </script>
> </button>
>
> Thank you in advance,
>
> Samuel
> ________________________________________________________
> Dojotoolkit: http://dojotoolkit.org
> Reference Guide: http://dojotoolkit.org/reference-guide
> API Documentation: http://dojotoolkit.org/api
> Tutorials: http://dojotoolkit.org/documentation
>
> Dojo-interest at mail.dojotoolkit.org
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.dojotoolkit.org/pipermail/dojo-interest/attachments/20120530/d269c4bf/attachment-0001.htm 


More information about the Dojo-interest mailing list