我试图在我的预先输入中返回一个json对象,而不仅仅是一个查询。我的想法是在自动完成菜单中传递其他字段,以帮助过滤结果。示例年份,品牌,型号,修剪。 json对象将包含filteredBy字段id和字段值。搜索make时的示例,json对象将包含过滤器字段id“year”和值“2013”加上当前字段id及其值。
目前这可以在下面工作,但只返回一个值。
return $field.typeahead({
replace: (uri, query) {
return extendURL(uri, "t:input": query);
}
}
这就是我尝试这样做的方式。
<input id="year" value="2013"/>
<input id="make" filterBy="year" value="ford"/>
<input id="model" filterBy="ford" value="fusion"/>
init = function(spec) {
var $field = $("#" + spec.id),
filterIdArray = [];
if (typeof spec.filterId !== 'undefined') {
filterIdArray = spec.filterId.split(',');
}
return $field.typeahead({
replace: function(uri, query) {
var params = {};
params["t:jsonStringField"] = searchField(spec.id, query);
params["t:jsonStringFilter"] = searchFilter(filterIdArray);
var stringify = JSON.stringify(params);
//I'm trying to pass back this stringified json object.
return extendURL(uri, stringify);
}
}
//The current search input
searchField = function(fieldId, query) {
return {name: fieldId, value: query};
};
//Additional fields used to create where clause within searchField
searchFilter = function(filterIdArray) {
var array = [];
//Field Id's and any fields being filtered by
for (var i = 0; i < filterIdArray.length; i++) {
var value = $("#" + filterIdArray[i]).val(),
name = filterIdArray[i];
array.push({name: name, value: value});
};
return array;
};
我最终收到以下错误。
“NetworkError:500内部服务器错误 - /TapDemo/sell/createlisting.year:autocomplete?category=aircraft&0=;&1=%22&2=t&3=:&4=j&5 = S和6 =的O&amp; 7 = N和8 = S和9 = T&安培; 10 =的R&amp; 11 = I&安培; 12 = N&安培; 13 =克和14 = F&安培; 15 = I&安培; 16 = E&安培; 17 = 1&安培; 18 = d&安培; 19 =%22安培; 20 =:&安培; 21 = {&安培; 22 =%22安培; 23 = N&安培; 24 = A&安培; 25 = M&安培; 26 = E&安培; 27 =%22安培; 28 =:安培; 29 =%22安培; 30 = Y&安培; 31 = E&安培; 32 = A&安培; 33 =的R&amp; 34 =%22及35 =,&安培; 36 =%22安培; 37 = v&安培; 38 = A&安培; 39 = 1&安培; 40 = U&安培; 41 = E&安培; 42 =%22安培; 43 =:&安培; 44 =%22安培; 45 = 5&安培; 46 =%22安培; 47 =}&安培; 48 =,&安培; 49 =%22安培; 50 = J&安培; 51 = S&安培; 52 =的O&amp; 53 = N&安培; 54 = S&安培; 55 = T&安培; 56 =的R&amp; 57 = I&安培; 58 = N&安培; 59 = G&安培; 60 = F&安培; 61 = I&安培; 62 = 1&安培; 63 = T&安培; 64 = E&安培; 65 =的R&amp; 66 =%22安培; 67 =:&安培; 68 = [&安培; 69 =&安培; 70 =}“
有人知道我做错了吗?
答案 0 :(得分:1)
您需要做的是,将这些值作为json编码发送,并确保将数据解码为数组,这样您就能够处理这些值。