Reputation: 1524
How to define XML store in Dojo 1.8 API
In old API we define it something like this
var store = new dojox.data.XmlStore({url: "books.xml", rootItem: "book"});
var gotBooks = function(items, request){
for(var i = 0; i < items.length; i++){
var item = items[i];
console.log("Located book: " + store.getValue(item, "title");
}
}
var request = store.fetch({query: {isbn:"A9B57*"}, onComplete: gotBooks});
Upvotes: 1
Views: 786
Reputation: 1524
This is books.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<books>
<book>
<isbn>1</isbn>
<title>Title of 1</title>
<author>Author of 1</author>
</book>
<book>
<isbn>2</isbn>
<title>Title of 2</title>
<author>Author of 2</author>
</book>
<book>
<isbn>3</isbn>
<title>Title of 3</title>
<author>Author of 3</author>
</book>
<book>
<isbn>4</isbn>
<title>Title of 4</title>
<author>Author of 4</author>
</book>
<book>
<isbn>5</isbn>
<title>Title of 5</title>
<author>Author of 5</author>
</book>
<book>
<isbn>6</isbn>
<title>Title of 6</title>
<author>Author of 6</author>
</book>
</books>
you can view this new API by using this code:
<script type="text/javascript" src="web/dojo/dojo.js" data-dojo-config="async: true"></script>
<script>
require(["dojox/data/XmlStore"],
function(XmlStore){
var store = new XmlStore({url: "http://localhost:8080/DojoProject/book.xml", rootItem: "book"});
var gotBooks = function(items, request){
for(var i = 0; i < items.length; i++){
var item = items[i];
console.log("Located book: " + store.getValue(item, "title"));
}
}
var request = store.fetch({query: {isbn:"1"}, onComplete: gotBooks});
});
</script>
Upvotes: 2