语义 UI 搜索模块不显示 json 响应
Semantic UI Search Module does not display json response
我正在尝试让语义 UI 的搜索自动完成工作。一切似乎都正常,除了自动完成总是说找不到结果。
这是一个示例搜索:
即使服务器响应似乎工作正常,情况也是如此。
这是服务器响应 JSON:
最后,这是我的 JQuery 代码:
$(".ui.search").search({
apiSettings: {
url : "/subtopics/search.json?query={query}"
},
fields: {
results : 'subtopics',
title : 'name'
},
minCharacters : 2
})
;
从我看到的所有示例来看,这是告诉语义 UI 要查看哪些字段的正确方法,但它不起作用。
非常感谢任何对此问题的帮助。
事实证明,使用语义 UI 文档 (http://semantic-ui.com/behaviors/api.html#response-callbacks) 中包含的 onResponse 回调是解决此问题的方法。
这是最终运行的代码:
$(".ui.search").search({
type: 'category',
minCharacters: 3,
apiSettings: {
onResponse: function(serverResponse) {
var
response = {
results: {}
}
;
//translate Server API response to work with search
$.each(serverResponse.subtopics, function(index, subtopic) {
var
topic = subtopic.topic || 'Unknown',
maxResults = 8
;
if(response.results[topic] === undefined) {
response.results[topic] = {
name: topic,
results: []
};
}
//add result to category
response.results[topic].results.push({
title: subtopic.name
});
});
return response;
},
url: "/subtopics/search.json?query={query}"
}
})
;
我正在尝试让语义 UI 的搜索自动完成工作。一切似乎都正常,除了自动完成总是说找不到结果。
这是一个示例搜索:
即使服务器响应似乎工作正常,情况也是如此。
这是服务器响应 JSON:
最后,这是我的 JQuery 代码:
$(".ui.search").search({
apiSettings: {
url : "/subtopics/search.json?query={query}"
},
fields: {
results : 'subtopics',
title : 'name'
},
minCharacters : 2
})
;
从我看到的所有示例来看,这是告诉语义 UI 要查看哪些字段的正确方法,但它不起作用。
非常感谢任何对此问题的帮助。
事实证明,使用语义 UI 文档 (http://semantic-ui.com/behaviors/api.html#response-callbacks) 中包含的 onResponse 回调是解决此问题的方法。
这是最终运行的代码:
$(".ui.search").search({
type: 'category',
minCharacters: 3,
apiSettings: {
onResponse: function(serverResponse) {
var
response = {
results: {}
}
;
//translate Server API response to work with search
$.each(serverResponse.subtopics, function(index, subtopic) {
var
topic = subtopic.topic || 'Unknown',
maxResults = 8
;
if(response.results[topic] === undefined) {
response.results[topic] = {
name: topic,
results: []
};
}
//add result to category
response.results[topic].results.push({
title: subtopic.name
});
});
return response;
},
url: "/subtopics/search.json?query={query}"
}
})
;