Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/419.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 基于另一个字段选择获取新值后更新下拉列表内容_Javascript_Jquery_Angularjs - Fatal编程技术网

Javascript 基于另一个字段选择获取新值后更新下拉列表内容

Javascript 基于另一个字段选择获取新值后更新下拉列表内容,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,我有一个视图,其中2个md自动完成字段绑定到值列表 当我选择第一个字段时,我发送一个GET请求以获取要绑定到下一个字段的值列表 我获取新列表并将第二个控件的值更新为新列表 但是,在UI中,第二个列表的值内容不会更新以显示新的列表值 第二个控件未使用新值刷新 我已尝试$scope.$apply() 但是,它不起作用。我的开发工具崩溃了 功能公司foctrl($state、$scope、genericInfo){ this.states=genericInfo.states; this.citie

我有一个视图,其中2个md自动完成字段绑定到值列表

当我选择第一个字段时,我发送一个GET请求以获取要绑定到下一个字段的值列表

我获取新列表并将第二个控件的值更新为新列表

但是,在UI中,第二个列表的值内容不会更新以显示新的列表值

第二个控件未使用新值刷新

我已尝试$scope.$apply()

但是,它不起作用。我的开发工具崩溃了

功能公司foctrl($state、$scope、genericInfo){
this.states=genericInfo.states;
this.cities=genericInfo.cities;
//当用户选择一个状态时
//使用所选州的新城市列表更新此.cities
//调用此方法,其中field=this.cities
功能(地址、字段){
if(地址和地址状态)
返回$http.get('http://localhost:8090/common/listofcitiesbystate/“+address.state)。然后(函数(响应){
字段=response.data;
})
}

}
模型未设置为脏状态,因此未使用新值刷新

在我的代码中,我以前将新值设置为:-

//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])
//1。清空数组
//2. 将元素从响应数组推送到UiElementArrayList
//i、 e。
而(this.cities.length>0)
this.cities.pop()
对于(i=0;i
这会将模型设置为脏状态并进行刷新,我可以看到新的列表元素。:)


如果您遇到同样的问题,请提出任何改进/更好的方法。

这是什么?是不是
CompanyInfoCtrl
在控制器中?这是companyinfoctrli
CompanyInfoCtrl
是一个控制器使用
$scope
而不是
this
将事物暴露在视图中,事情会更愉快。好的,我试试看。我确实试过了。但我想我会在某个地方犯错误。我将再次尝试使用$scope。@实际上,如果MaxSorin使用
contoller作为
语法
这个
就可以了,他不需要
$scope