Accessing JSON object after event completed

狂风中的少年 提交于 2019-12-11 23:26:14

问题


Context

I am using the jquery ui autocomplete control and that is working fine. From my understanding, this control is creating an unordered list and for each item in the list, the JSON object that I am asking for is "attached" to it. See image below

Some code

<ul class="ui-autocomplete ui-menu ui-widget ui-widget-content ui-corner-all" role="listbox" aria-activedescendant="ui-active-menuitem" style="z-index: 1; top: 444px; left: 48px; display: block; width: 118px;">
<li class="ui-menu-item" role="menuitem"><a class="ui-corner-all" tabindex="-1">PartNum 1</a></li>
<li class="ui-menu-item" role="menuitem"><a class="ui-corner-all" tabindex="-1">PartNum 2</a></li>

Then on the close event of jquery ui autocomplete, I tried the following

close: function (event, ui) {
    var termInput = $(this).val().toLowerCase();
    var $autocompleteList = $('ul.ui-autocomplete li a');
    $autocompleteList.each(function () {
        if ($(this).text().toLowerCase() == termInput) {
            var $parentItem = $(this).parent();
            return;
        }
    });

EDIT - following a request for such an example

jsFiddle example

http://jsfiddle.net/mxzuF/

Question

How do I actually access these objects using jQuery outside of any "events" associated with jquery ui autocomplete? The fact is that I want to access these objects after the control has finished "executing". Effectively, I'm trying to access the objects associated with the $parentItem.

来源:https://stackoverflow.com/questions/6787644/accessing-json-object-after-event-completed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!