2013-10-06 44 views
0

我有一个dojox.data.XmlStore我想用XPath查询xml存储。有没有办法做到这一点? 下面的示例代表对属性的查询,但我想使用item元素提供的XPath查询。DOJO - 使用XPath查询XmlStore

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}); 

例如,如果我有一个道场dijit.Tree元素,它支持的onClick事件,我希望能够获取所选元素的内容。 item元素有一个名为“query”的字段,它表示项目本身的XPath查询。 如何使用此XPath查询来从商店中获取数据?

var tree = new Tree({ 
    model: myModel, 
    onClick: function(item){ 
     //the item parameter has a field called "query" that represent the XPath query for the item itself. 
    } 
}); 

如果我使用的是从XmlItem没有结果“查询”字段中提供。 var request = store.fetch({query: item.q , onComplete: gotBooks});

回答

0

尝试使用正则表达式,而不是 “*” 在您的查询,如:

var request = store.fetch({query: {isbn:new RegExp('A9B57','i')}, onComplete: gotBooks}); 

如果你需要查询所有,只需使用:

var request = store.fetch({query: {}, onComplete: gotBooks}); 
0

XmlStore我们可以提取数据使用查询XmlItem提供,如下例所示。

答案是道场源发现的dijit /树/ ForestStoreModel#的getChildren()

store.fetch({ 
      //for the query element the item.query field can be used in this way 
      query: item.query, 
      onComplete: onComplete, 
      onError: onError 
});