以下是输入文本元素的jsp页面标记:
<input name="searchTextSpan" id="searchTextSpan" type="text"/>
下面是在dcument.ready上加载的ajax调用:
AUI().use("liferay-portlet-url", function(A) {
var resourceURL = Liferay.PortletURL.createResourceURL();
resourceURL.setPortletId("app_war_portlet");
resourceURL.setResourceId(resourceId);
require(["dojo/request", "dijit/registry", "dojo/on", "dojo/domReady!"], function(request){
request.post(resourceURL.toString(), {
query: ajaxData,
handleAs: "json"
}).then(function(data){
if(resourceId == 'inputTextClick'){
AUI().use("liferay-portlet-url", function(A) {
var resourceURL = Liferay.PortletURL.createResourceURL();
resourceURL.setPortletId("app_war_portlet");
if(data.cachetmpArr!=null && data.cachetmpArr.length>0){
var cacheList = JSON.stringify(data.cachetmpArr);
cacheList = cacheList.replace(/"/g, "'");
console.log('cacheList12 '+cacheList);//['106182233','206182233','306182233'];
$('#searchTextSpan').autocomplete({
width: 300,
max: 10,
delay: 100,
minLength: 1,
autoFocus: true,
cacheLength: 1,
scroll: true,
highlight: false,
source:cacheList,
}).focus(function(){
$(this).autocomplete("search", "");
});
}
});
}
});
})
})
source属性不接受cacheList,它会抛出404 url错误。 你能建议吗
答案 0 :(得分:0)
在将{J}传递给parse
之前,您需要autocomplete
JSON。
像这样:
$('#searchTextSpan').autocomplete({
width: 300,
max: 10,
delay: 100,
minLength: 1,
autoFocus: true,
cacheLength: 1,
scroll: true,
highlight: false,
source:JSON.parse(cacheList), // parse JSON response
}).focus(function(){
$(this).autocomplete("search", "");
});