我已按照 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>