我已关注http://www.liferaysavvy.com/2014/02/liferay-aui-auto-complete-list.html自动完成,我从服务器获取以下格式的数据(在代码中:
alert('jsonArray came: ' + jsonArray))
给出了以下内容,
[
{
"roleName": "Organization User",
"roleId": 10147
},
{
"roleName": "Site Admin",
"roleId": 16883
},
{
"roleName": "Student",
"roleId": 18139
},
{
"roleName": "Parent",
"roleId": 18146
},
{
"roleName": "Faculty",
"roleId": 18153
},
{
"roleName": "SchooloneStudent",
"roleId": 27701
}
]
,但是从代码:new A.AutoCompleteList它无法获取数据。任何人都可以帮助我吗?
<aui:script>
AUI().use('autocomplete-list','aui-base','aui-io-request','autocomplete-filters','autocomplete-highlighters',function (A) {
A.io.request('<%=getRoles%>',{
dataType: 'json',
method: 'GET',
on: {
success: function(event, id, obj) {
var instance = this ;
var data = instance.get('responseData');
var jsonArray = JSON.stringify(data);
alert('result came: ' + data);
alert('jsonArray came: ' + jsonArray);
try {
new A.AutoCompleteList(
{
allowBrowserAutocomplete: 'false',
activateFirstItem: 'true',
inputNode: '#<portlet:namespace />ListOfRoles',
resultTextLocator: 'roleName',
render: 'true',
resultHighlighter: 'phraseMatch',
resultFilters:['phraseMatch'],
source:jsonArray,
});
}catch(e) {
alert('not working : ' + e);
}
}
}
});
});
</aui:script>
答案 0 :(得分:0)
我认为您不需要表示响应,因为您已经获得了JSON格式的响应。可能有一些数据不匹配...... 试试这个:
<aui:script>
AUI().use('autocomplete-list','aui-base','aui-io-request','autocomplete-filters','autocomplete-highlighters',function (A) {
A.io.request('<%=getRoles%>',{
dataType: 'json',
method: 'GET',
on: {
success: function(event, id, obj) {
try {
new A.AutoCompleteList(
{
allowBrowserAutocomplete: 'false',
activateFirstItem: 'true',
inputNode: '#<portlet:namespace />roleNames',
resultTextLocator: 'roleName',
render: 'true',
resultHighlighter: 'phraseMatch',
resultFilters:['phraseMatch'],
source:this.get('responseData'),
autoLoad:false,
sync:false,
});
}catch(e) {
alert('not working: ' + e);
}
}
}
});
});
</aui:script>
谢谢,
〜CHANDAN