문제

My ui-autocomplete should send ajax request to different path's. My script changes this path on change select event. But event do not updates and sends request to old url.

I tried live(), on(), livequery(). nothing works.

How to update event?

My input autocomplete field:

<input class="specialization_names ui-autocomplete-input" data-autocomplete-source="/specializations">

I'm changing data-autocomplete-source

Event I'm binging next way(generated by coffeescript)

_ref = $('.specialization_names');
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  input = _ref[_i];
  $(input).on('focus', function() {
    return $(input).catcomplete({
      source: $(input).data('autocomplete-source')
    });
  });
}

or change on() to live() or to plugin livequery

This code changing url on select.

var select, _i, _len, _ref;

_ref = $('.resume_scopes');
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  select = _ref[_i];
  $(select).on('change', function() {
    var scope_id;
    scope_id = $(this).children("option:selected").attr('value');
    return $(this).siblings('.specialization_names').attr("data-autocomplete-source", "/specializations/" + scope_id);
  });
}

Is there any way to manually refresh one time an event?

도움이 되었습니까?

해결책

jQuery's .data only reads from the data-* attribute once (the 1st time you call .data on the element to get the value). .attr updates the attribute on the element, but jQuery's .data has cached the value. It you want to update it, try using .data instead.

return $(this).siblings('.specialization_names').data("autocomplete-source", "/specializations/" + scope_id);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top