1
我使用Solr's JSON output for AJAX example作爲我的項目的基礎。不過,我通過在表單中添加下拉菜單修改了一些內容,並將其添加到了參數中。Solr&AJAX設置響應查詢正確
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>
我想下拉值添加到我的面查詢結果爲這樣:
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;
我的方面響應發回:實體:[對象對象] .Universal。如何正確地將下拉值添加到響應查詢中,以便Solr實際返回適當的構面值?非常感謝。
感謝您的答覆。 console.log顯示窗口<正確的對象在firebug中:brand1 [「Eve2」,10,「RHCP」,6] brand2 \t [「Black_Keys」,6,「White_Stripe」,5] brand3 [「SoaD」,5, BoB「,3] brand4 \t [」Doors「,3,」Cage_Elephant「,2]。如果我靜態插入4個品牌中的任何一個(rsp.facet_counts.facet_fields.brand1),我會從Solr獲得正確的方面結果。然而,我不知道爲什麼從實體下拉動態添加brand1作爲var與'+'在我身上咳嗽... – Chris
你沒有動態地做它,你強制錯誤地強制類型。製作這些項目的正確方法是創建一個for循環,其中爲每個陣列成員引用了rsp.facet_counts.facet_fields對象。 for(var x in rsp.facet_counts.facet_fields){//用rsp.facet_counts.facet_fields [x]做一些事情:) – Kristian
y ...這樣做,非常感謝這堂課 – Chris