我试图将dojo dgrid连接到solr数据服务并需要一些帮助。
当我使用jsonp
时,我可以连接到solr数据并将数据结果输出到屏幕,如下所示:
dojo.require(" dojo.io.script&#34);
function searchGoogle(){
//查找我们将文本粘贴在下面的节点。
var targetNode = dojo.byId(" output");
// The parameters to pass to xhrGet, the url, how to handle it, and the callbacks.
var jsonpArgs = {
url: "myExternalSolrURL",
callbackParamName: "json.wrf",
content: {
wt: "json",
rows: "12",
start: "1",
q: "*"
},
load: function(data){
// Set the data from the search into the viewbox in nicely formatted JSON
targetNode.innerHTML = "<pre>" + dojo.toJson(data, true) + "</pre>";
},
error: function(error){
targetNode.innerHTML = "An unexpected error occurred: " + error;
}
};
dojo.io.script.get(jsonpArgs);
}
dojo.ready(searchGoogle);
但是,当我尝试使用jsonrest
连接到solr数据并让它显示在dgrid中时,似乎没有任何事情发生。这是我的代码:
<script>
var myStore, dataStore, grid;
require([
"dojo/store/JsonRest",
"dojo/store/Memory",
"dojo/store/Cache",
"dgrid/Grid",
"dojo/data/ObjectStore",
"dojo/query",
"dijit/form/Button",
"dojo/domReady!"
], function (JsonRest, Memory, Cache, Grid, ObjectStore, query, Button, domReady) {
myStore = Cache(JsonRest({
target: "myExternalSolrURL",
idProperty: "id"
}),
Memory({ idProperty: "id" }));
grid = new Grid({
store: dataStore = ObjectStore({ objectStore: myStore }),
structure: [
{ name: "Thing id", field: "id", width: "50px" },
{ name: "Name", field: "name", width: "200px" },
{ name: "detail", field: "detail", width: "200px" }
]
}, "grid"); // make sure you have a target HTML element with this id
grid.startup();
});
</script>
<div style="height: 300px; width: 600px; margin: 10px;">
<div id="grid">
</div>
</div>
有人看到我错过的东西吗?
答案 0 :(得分:0)
dojo/data
商店。 dgrid仅支持dojo/store
API,因此请停止将商店包装在ObjectStore
。dgrid/List
和dgrid/Grid
不包含商店逻辑。您需要使用dgrid/OnDemandGrid
或混合dgrid/extensions/Pagination
。dojo/store/JsonRest
actually behaves as the store implementation expects确保您使用的服务(或使用或编写不同的dojo/store
实施方案)答案 1 :(得分:0)
显然,问题的一部分是Solr索引不是像网格或dgrid可以处理的平面数据结构。如果你有像Solr或ElasticSearch索引那样返回的嵌套数据将返回它必须是&#34; flattened&#34;进入一个网格。但是,这种数据层次结构将适用于树与网格。因此,接下来的挑战是连接到索引并将其展平。