如何在Dojo 1.8 API中定义XML存储
在旧的API中我们定义类似这样的
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});
答案 0 :(得分:2)
这是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>
您可以使用以下代码查看此新API:
<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>