简体   繁体   中英

How to get selected item from AUI autocomplete list

I want to show address in my database to an autocomplete aui input field.Everything seems working fine.But im not able to retrive the address number of the record.How to use the on change event of autocomple-list or how can i access the selected item's json object

  @Override
        public void serveResource( ResourceRequest resourceRequest, ResourceResponse resourceResponse ) throws IOException,
                PortletException
        {


            String cmd = ParamUtil.getString(resourceRequest, "get_address");
            String myInputNode = ParamUtil.getString(resourceRequest, "addressAutocomplete");

            System.out.println("addressAutocomplete"+myInputNode);
            if (cmd.equals("get_address")) {
             getUsers(resourceRequest, resourceResponse,myInputNode);
            }
            }


    private void getUsers(ResourceRequest resourceRequest, ResourceResponse resourceResponse, String myInputNode) throws IOException, PortletException {

                JSONArray usersJSONArray = JSONFactoryUtil.createJSONArray();
                ThemeDisplay themeDisplay =    (ThemeDisplay)resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);
                JSONObject userJSON=null;
                try {
                List<AddressMaster> userList=AddressMasterLocalServiceUtil.getAllAddressBySearchKey( myInputNode );
                                           for(AddressMaster addressMaster:userList){
                userJSON=JSONFactoryUtil.createJSONObject();
                userJSON.put("addressNumber",addressMaster.getAdrNummer());

                userJSON.put( "address",  addressMaster.getAddress())
         );

                       usersJSONArray.put(userJSON);
                }
                } catch (Exception e) {
                }
                PrintWriter out=resourceResponse.getWriter();
                out.println(usersJSONArray.toString());

                System.out.println("usersJSONArray"+usersJSONArray.toString());



            }

Jsp File

<portlet:resourceURL var="getAddress">
   <portlet:param name="get_address" value="get_address" />
 </portlet:resourceURL>


 <aui:input id="addressAutocomplete"  name="addressAutocomplete" label="group_choose_address"   style="width:700px"/>

<aui:script>
AUI().use('autocomplete-list','aui-base','aui-io-request','autocomplete-filters','autocomplete-highlighters',function (A) {
A.io.request('<%=getAddress%>',{
dataType: 'json',
method: 'GET',
on: {
success: function() {
//continents=this.get('responseData');
//alert(continents[0].name);
new A.AutoCompleteList(
{
allowBrowserAutocomplete: 'true',
activateFirstItem: 'true',
inputNode: '#<portlet:namespace/>addressAutocomplete',
resultTextLocator: 'address',
resultHighlighter:['phraseMatch'],
resultFilters:['phraseMatch'],
render: 'true',
source:this.get('responseData'),
});
}}
});                  
});
</aui:script>

It's a bit tricky to see exactly what'll be coming, but I think you could do:

var address_ac = new A.AutoCompleteList({... as you have it...});
address_ac.on('select', function (e) {
    var selected_node = e.itemNode,
        selected_data = e.result;
});

Docs here: http://alloyui.com/versions/1.5.x/api/classes/AutoCompleteList.html#events

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM