Using django-automcomplete-light V3 and angular on a non admin page.
Using the widget autocomplete.ModelSelect2
在非管理页面上使用django-automcomplete-light V3和angle。使用小部件autocomplete.ModelSelect2
Where is the selected value stored? Using firebug, it's not in a new hidden html element and if i attempt to watch the original (now hidden) select element, it's value never changes if I change the selected value in the autocomplete widget.
选择的值存储在哪里?使用firebug,它不在一个新的隐藏的html元素中,如果我尝试查看原始的(现在隐藏的)select元素,如果我更改autocomplete小部件中所选的值,那么它的值不会改变。
How can angular watch/read this value?
角式手表如何读取这个值?
Update:
As @visegan below points out you can use jquery syntax to get the value but for some reason you can't watch it.
更新:正如下面的@visegan所指出的,您可以使用jquery语法来获取该值,但是由于某些原因,您不能观看它。
i.e. this watch never gets triggered:
也就是说,手表永远不会被触发:
$scope.$watch(function(){
return $('#id_field').val();
},
function(newVal, oldVal){
console.log('current %r', newVal);
$scope.models.foo=parseInt(newVal);
});
1 个解决方案
#1
1
Well I have just tried with my project and it was pretty straight forward:
我刚刚尝试了我的项目,非常直接:
$('#id_field').val()
To be honest, I am also not sure where exactly does the value come from.
老实说,我也不确定这些价值到底来自哪里。
As for the change watcher: autocomplete light now uses select2 component, which is apparently a bit problematic with angular. There are two approaches that works: first one is to add more jquery:
至于变化观察者:自动补全光现在使用select2组件,这显然有点问题。有两种方法是有效的:第一种是添加更多jquery:
$('#id_field').change(function() {alert('changed')});
This I have tested. The other approach is to do it somehow natively. Look at Select2 event handling with Angular js
我已经测试了。另一种方法是以某种天生的方式去做。看看带有角度js的Select2事件处理
#1
1
Well I have just tried with my project and it was pretty straight forward:
我刚刚尝试了我的项目,非常直接:
$('#id_field').val()
To be honest, I am also not sure where exactly does the value come from.
老实说,我也不确定这些价值到底来自哪里。
As for the change watcher: autocomplete light now uses select2 component, which is apparently a bit problematic with angular. There are two approaches that works: first one is to add more jquery:
至于变化观察者:自动补全光现在使用select2组件,这显然有点问题。有两种方法是有效的:第一种是添加更多jquery:
$('#id_field').change(function() {alert('changed')});
This I have tested. The other approach is to do it somehow natively. Look at Select2 event handling with Angular js
我已经测试了。另一种方法是以某种天生的方式去做。看看带有角度js的Select2事件处理