根据另一个字段选择获取新值后更新下拉列表内容
Update the dropdown contents after GET new value based on another field selection
我有一个View,其中有2个md自动完成字段绑定到值列表。
当我选择第一个字段时,我会发送一个GET请求,以获取要绑定到下一个字段的值列表。
我得到了新列表,并将我的第二个控件的值更新为新列表。
但是,在UI中,第二个列表的值内容没有被更新以显示新的列表值。
第二个控件未使用新值刷新。
我试过$scope$apply()。
但是,它不起作用。我的开发工具崩溃了。
function CompanyInfoCtrl($state, $scope, genericInfo) {
this.states = genericInfo.states;
this.cities = genericInfo.cities;
//when user Selects a State
//Update this.cities with the new ListOfCities in the selected State
//Call this method where field = this.cities
function(address, field) {
if(address && address.state)
return $http.get('http://localhost:8090/common/listofcitiesbystate/' + address.state).then(function(response){
field = response.data;
})
}
}
模型没有设置为Dirty状态,因此没有用新值刷新。
在我的代码中,我之前将新值设置为:-
//where UiElementArrayList is a list of object and is bind to md autocomplete
//I need to update the list with new valueList based on User Action/Selection
//GET call to fetch new data
this.cities = response.data
这解决了问题:-
//1. Empty the array
//2. Push the elements from the Response array to the UiElementArrayList
//i.e.
while(this.cities.length > 0)
this.cities.pop()
for(i=0; i < response.data.length; i++)
this.cities.push(response.data[i])
这将模型设置为脏状态并进行刷新,我可以看到新的List元素。:)
如果你遇到同样的问题,请提出任何改进/更好的方法。
相关文章:
- 如何在从下拉列表中选择不同的值后更新和调用javascript函数
- 下拉列表未从计算的可观察项更新
- 引导程序 3 下拉列表不会更新
- 使用AngularJS更新下拉列表
- 根据另一个字段选择获取新值后更新下拉列表内容
- 下拉列表选择的值在UI淘汰js中没有更新
- 如果选择/下拉列表发生更改,则Mysql会更新
- 通过下拉列表动态更新总数
- 从knockout.js中的下拉列表更新对象
- 基于第一多选下拉列表更新第二多选下拉列表
- 通过从下拉列表中选择来更新GoogleMaps InfoWindow
- 播放框架:从下拉列表中选择值时更新网页
- 在 Javascript URL 中传递两个变量,以根据传递的值更新下拉列表
- 使用 JavaScript 单击复选框时更新下拉列表框内容
- Django:自动更新下拉列表会导致“form.is_valid()”返回false
- 正在从json消息更新下拉列表,代码不起作用
- 如何使用服务器生成的数组中的值动态更新下拉列表选项
- angularjs无法更新下拉列表更改的指令
- 动态更新下拉列表与jquery
- 使用minimalect更新下拉列表