dongmi4927 2018-05-16 12:37
浏览 129
已采纳

将json数组更新为数据自动完成后,它不会更新data-autocomplete的值

I am creating a dynamic form for a hospital. Here i have a problem with data-autocomplete. The problem is after updating json array to data-autocomplete=' ' it is not updating the value of data-autocomplete=' '. AS I am using html(bootstrap) and php templete for my frontend forms so,all links are properly arrenged and one input element similar to this is working fine but i have updated the values using php for that input.

Html code

<input type='text' class="form-control ui-autocomplete-input" data-autocomplete='' autocomplete="off" id="patient_type_desc" name="patient_type_desc" class="form-control" />

JQuery Code

$.post(url, {"referral":referral}, function(data){
   //console.log(data);
   $('#patient_type_desc').attr('data-autocomplete', data);
});

This code is updating the value, but in form autocomplete is not populating with suggestions.

The data variable is like below

["name1","name2"]

I tried with this jQuery code also but no use - This code not at all working

$( "#patient_type_desc" ).autocomplete({
  source: data
});
  • 写回答

2条回答 默认 最新

  • doulu4976 2018-05-17 05:24
    关注

    My Jquery is like this now

    $.post(url, {"referral":referral}, function(data){
                    //console.log(data);
                    $( "#patient_type_desc" ).autocomplete({
                        source: data
                    });
                        //$('#patient_type_desc').attr('data-autocomplete', data);
                    }, "json");
    

    Finally working by adding "json". Thank you for all bro's.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?