django-autocomplete-light向查询网址添加参数 [英] django-autocomplete-light add parameter to query url
问题描述
我正在尝试将一些数据传递给 autocomplete_light.AutocompleteModelBase
,以便可以从搜索中排除一些模型.我正在尝试在文档此处中使用依赖关系"信息
I'm trying to pass some data along to the autocomplete_light.AutocompleteModelBase
so I can exclude some models from the search. I'm trying to use the Dependencies info in the docs here
但是我似乎可以得到它.
but I can seem to get it.
输入的ID为 id_alternate_version-autocomplete
,所以我正在尝试:
The id of the input is id_alternate_version-autocomplete
, so I'm trying:
$("#id_alternate_version-autocomplete").yourlabsWidget().autocomplete.data = {'id': 'foo'};
但是被调用的网址看起来像 http://127.0.0.1:8000/autocomplete/FooAutocomplete/?q=bar
But the url called looks like http://127.0.0.1:8000/autocomplete/FooAutocomplete/?q=bar
我想要: http://127.0.0.1:8000/autocomplete/FooAutocomplete/?q=bar&id=foo
我该怎么做?
推荐答案
这是我的方法:
$(document).ready(function() {
$('form#recipe').on('change propertychange keyup input paste', function() {
var ingredient_item_type = $("form#recipe input[type='radio']:checked").val();
var widget = $("form#recipe input#id_ingredients_text").parents('.autocomplete-light-widget');
if(ingredient_item_type) {
widget.yourlabsWidget().autocomplete.data['hello'] = 'world';
}
});
});
除了Java杂技,主要的观察结果是:
Javascript acrobatics aside, the key observation is thus:
您在自动完成窗口小部件的 .data
对象中放入的所有内容自动成为GET请求的一部分.HTH.
anything you put in the .data
object of the autocomplete widget will
automatically be made part of the GET request. HTH.
这篇关于django-autocomplete-light向查询网址添加参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!