[英]Connecting dojo dgrid to solr
I'm trying to connect a dojo dgrid to a solr data service and need some help. 我正在尝试将dojo dgrid连接到solr数据服务,并且需要一些帮助。 When I use jsonp
I can get connected to the solr data and output the data result to the screen with something like this: dojo.require("dojo.io.script"); 当我使用jsonp
我可以连接到solr数据并将数据结果输出到屏幕上,如下所示:dojo.require(“ dojo.io.script”); function searchGoogle(){ // Look up the node we'll stick the text under. function searchGoogle(){//查找将文本粘贴在其下的节点。 var targetNode = dojo.byId("output"); 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);
But, when I try to use jsonrest
to connect to the solr data and get it to show up in a dgrid nothing appears to happen. 但是,当我尝试使用jsonrest
连接到solr数据并将其显示在dgrid中时,似乎没有发生任何事情。 This is the code I have for that: 这是我的代码:
<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>
Does anyone see what I am missing? 有人看到我想念的吗?
dojo/data
store with dgrid. 您已将代码更改为使用dgrid,但看起来您仍在尝试将dgrid与dojo/data
存储一起使用。 dgrid only supports the dojo/store
API, so stop wrapping your store in ObjectStore
. dgrid仅支持dojo/store
API,因此请停止将您的商店包装在ObjectStore
。 dgrid/List
and dgrid/Grid
do not contain store logic. dgrid/List
和dgrid/Grid
不包含存储逻辑。 You will want to either use dgrid/OnDemandGrid
or mix in dgrid/extensions/Pagination
. 您将要使用dgrid/OnDemandGrid
或混入dgrid/extensions/Pagination
。 dojo/store/JsonRest
actually behaves as the store implementation expects (or use or write a diffrent dojo/store
implementation) 确保您与dojo/store/JsonRest
一起使用的服务的行为确实符合商店实现的预期 (或使用或编写不同的dojo/store
实现) Apparently part of the problem is that a Solr index is not a flat data structure like a grid or dgrid can deal with. 问题的一部分显然是Solr索引不是像网格或dgrid可以处理的平面数据结构。 When you have nested data returned like a Solr or ElasticSearch index will return it must be "flattened" to go into a grid. 当您像Solr或ElasticSearch索引一样返回嵌套数据时,必须将其“展平”才能放入网格。 However, this sort of hierarchy of data will work with a tree vs a grid. 但是,这种数据层次结构将适用于树与网格。 So the next challenge is to connect to the index and flatten it. 因此,下一个挑战是连接到索引并将其展平。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.