我使用Solr's JSON output for AJAX example作为我项目的基础。但是我通过在表单中添加一个下拉菜单来修改内容,并在params中添加了faceting。
PARAMS:
function getstandardargs() {
var params = [
'wt=json'
,'facet=true'
,'facet.field=brand1'
,'facet.field=brand2'
,'facet.field=brand3'
,'facet.field=brand4'
,'facet.limit=2'
];
下拉菜单:
<form name="f1" onsubmit='xmlhttpPost("/solr/select"); return false;'>
<p>query: <input name="query" type="text">
<select id="Entity">
<option value="brand1">Universal</option>
<option value="brand2">Paramount</option>
<option value="brand3">Fox</option>
<option value="brand4">Sony</option>
</select>
<input value="Go" type="submit"></p>
我正在尝试将下拉值添加到我的facet查询结果中:
var rsp = eval("("+str+")");
var c=document.getElementById("Entity");
cat=c.options[c.selectedIndex].value;
var output=rsp.facet_counts.facet_fields;
html += "Entity: " + output+'.'+cat;
我的方面响应发回:实体:[object Object] .Universal 。如何正确地将下拉值添加到响应查询中,以便Solr实际上可以返回正确的构面值?非常感谢。
答案 0 :(得分:2)
您无疑会通过为ajax请求使用库来降低此问题的复杂性,因为:
eval
既然你说你的回答是“实体:[对象对象]。通用”,你能否尝试使用console.log( output );
告诉我们对象中返回的是什么,正式?有可能通过将字符串与对象连接起来,你搞乱了输出对象
如果它实际上是一个对象,你可以像这样迭代地访问它:
for(var x in rsp.facet_counts.facet_fields) {
//rsp.facet_counts.facet_fields[x]
}