【问题标题】:django-autocomplete-light on fetch datadjango-autocomplete-light 获取数据
【发布时间】:2013-04-09 09:47:44
【问题描述】:

自动完成灯。 谁能帮我。如果自动编译什么都不返回(对象还不存在),我想显示按钮“添加”。我在哪里可以检查从后端自动完成的内容。

类似的东西

$('#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. 
    }
})

非常感谢。

【问题讨论】:

    标签: jquery django django-autocomplete-light


    【解决方案1】:

    test_project 中有一个示例(我只是为了好玩而做的),请在/admin/ajax_create/creatable/add/ 中尝试。这可能不是最好的方法,也可能不是完全您想要的,但它确实是一个非常好的开始。你可以测试它here。您可以通过膨胀 javascript 轻松地将其调整为您的确切规格。

    相反,我建议只使用 add-another。

    【讨论】:

    【解决方案2】:

    这可能有助于节省一些时间。我的解决方案是: 添加 this.input.trigger('fetch', jqXHR); 到 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
               }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-20
      • 1970-01-01
      • 2017-03-26
      • 1970-01-01
      • 2015-10-15
      • 2013-01-06
      • 2016-10-12
      • 1970-01-01
      相关资源
      最近更新 更多