There are two types of data storage in dojo:
eg:.
You have an array of countries and you want to use it for filtering:
[{ abbr: 'ec', name: 'Ecuador', capital: 'Quito' }, { abbr: 'eg', name: 'Egypt', capital: 'Cairo' }, { abbr: 'et', name: 'Ethiopia', capital: 'Addis Ababa' }]
First of all, you need to create a data warehouse js variable for ItemFileWriteStore.
<script> dojo.require("dojo.data.ItemFileWriteStore"); dojo.require("dijit.form.FilteringSelect"); var storeData = { identifier: 'abbr', label: 'name', items: </script>
The next step is to declare the filtering option and itemFileWriteStore in the html markup:
<div dojotype="dojo.data.ItemFileWriteStore" data="storeData" jsid="countryStore"></div> <div dojotype="dijit.form.FilteringSelect" store="countryStore" searchattr="name" id="filtSelect"></div>
And finally, create special functions for adding / removing / changing elements in the filter selection:
Add new item:
function addItem() { var usa = countryStore.newItem({ abbr: 'us', name: 'United States', capital: 'Washington DC' }); }
I hope everything is clear here. Just a small note: the "identifier" field ("abbr" in our case) must be unique in memory
Delete items - for example. deleting all items with the name "United States of America"
function removeItem() { var gotNames = function (items, request) { for (var i = 0; i < items.length; i++) { countryStore.deleteItem(items[i]); } } countryStore.fetch({ query: { name: "United States of America" }, queryOptions: { ignoreCase: true }, onComplete: gotNames }); }
As you can see, I created a query that finds items with the name == "United States of America" ββin the data warehouse. After the request is completed, the "gotNames" function will be called. The gotNames function removes all items that return a request.
And the last function is Edit item.
It looks like a delete function. only one difference:
you must use the setValue() method itemFileWriteStore to change the property of the element:
countryStore.setValue(item, "name", newValue);
Here is a page with a working example.