简体   繁体   English

django-autocomplete-light获取数据

[英]django-autocomplete-light on fetch data

autocomplete-light. 自动补光。 Can any one help me. 谁能帮我。 I want to show button 'add' if autocomplite return nothing (Object does not exists yet). 如果自动填充不返回任何内容(对象尚不存在),我想显示按钮“添加”。 Where can I check what get autocomplite from back-end. 我在哪里可以检查从后端获取自动填充的内容。

Something like this 像这样

$('#myauto_field').yourlabsAutocomplete({
    fetch: function() { //Override fetch function
        //call fetch from jQuery
        //get data and see is it empty or note. If empty show button. 
    }
})

Thank you very much. 非常感谢你。

There's an example in test_project (which I just did for fun), try it in /admin/ajax_create/creatable/add/ . test_project中有一个示例(我只是为了好玩而已),请在/admin/ajax_create/creatable/add/尝试。 It's maybe not the best way and maybe not exactly what you want, but it sure is a really good start. 这也许不是最好的方式,也许不是你想要什么 ,但可以肯定的是一个非常好的开始。 You can test it here . 您可以在这里进行测试。 You can easily adapt it to your exact specifications by bloating the javascript. 您可以通过使JavaScript膨胀来轻松地使其适应您的确切规格。

Instead, I'd recommend just using add-another. 相反,我建议只使用add-another。

May be this help's some one to save some time. 也许这可以帮助您节省一些时间。 My solution is: Add this.input.trigger('fetch', jqXHR); 我的解决方案是:添加this.input.trigger('fetch', jqXHR); to autocomplite.js function yourlabs.Autocomplete.prototype.fetchComplete and put bind fetch for autocomplite input field 到autocomplite.js函数yourlabs.Autocomplete.prototype.fetchComplete并将绑定获取放入autocomplite输入字段

$('#' + fieldid).yourlabsAutocomplete({})
     .input.bind('fetch', function(e, replay){
           if(replay.responseText.indexOf("No matches found") == -1){
              //Here code if object not found
           }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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