Javascript 带有来自带有angularjs的服务器的值的嵌套选择为空
我有两个嵌套的选择,在一个表单中表示州和市。当用户选择并保存表单时,一切正常,但当保存的数据来自服务器时,第二次选择不会显示相应变量的值,尽管其值正确。有人知道这是我的错吗?非常感谢您的帮助 HTML 编辑方法调用的函数,包括 选择所需的Javascript 带有来自带有angularjs的服务器的值的嵌套选择为空,javascript,angularjs,html,Javascript,Angularjs,Html,我有两个嵌套的选择,在一个表单中表示州和市。当用户选择并保存表单时,一切正常,但当保存的数据来自服务器时,第二次选择不会显示相应变量的值,尽管其值正确。有人知道这是我的错吗?非常感谢您的帮助 HTML 编辑方法调用的函数,包括 选择所需的 Thank's但是当保存的数据来自服务器时,第二个选择不会显示相应变量的值,尽管它的值正确-我认为来自服务器的数据是通过ajax请求检索的?您能澄清相应变量的值吗?Zack,所选城市值是一个整数,即城市ID请在状态和城市变量中添加示例数据。还提供从API检索的
Thank's但是当保存的数据来自服务器时,第二个选择不会显示相应变量的值,尽管它的值正确-我认为来自服务器的数据是通过ajax请求检索的?您能澄清相应变量的值吗?Zack,所选城市值是一个整数,即城市ID请在
状态
和城市
变量中添加示例数据。还提供从API检索的响应示例。
<div class="form-group">
<label for="selectState" class="col-sm-2 control-label">Estado</label>
<div class="col-sm-4">
<select id="selectState" class="form-control" ng-model="selected_state">
<option disable value="">Escolha um estado... </option>
<option ng-selected="selected_state == state.id" ng-repeat="state in states" value="{{state.id}}" >{{state.description}}</option>
</select>
</div>
</div>
<div class="form-group">
<label for="selectCity" class="col-sm-2 control-label">Cidade</label>
<div class="col-sm-4">
<select id="selectCity" class="form-control" ng-model="selected_city" >
<option disable value="">Escolha uma cidade... </option>
<option id="optionCity" ng-selected="selected_city == city.id" ng-repeat="city in cities" value="{{city.id}}" >{{city.description}}</option>
</select>
</div>
</div>
$scope.$watch('selected_state', function(newVal) {
if (newVal) load_cities_by_state($http, $scope, $cookies, $scope.selected_state, $cookieStore);
});
function detail_office($http, $scope, $cookies, $cookieStore, $timeout){
var req = {
method: 'GET',
url: URL,
headers: {
'x-csrftoken' : $cookies.get('csrftoken'),
'authorization': getAuthorizationToken($cookieStore)
}
}
$http(req).then(function(response) {
$scope.editingOffice = true;
$scope.start_office = new Date(response.data.start);
if (response.data.end != null){
$scope.end_office = new Date(response.data.end);
}
$scope.selected_state = response.data.state;
$scope.selected_office=response.data.office_type;
$scope.selected_city = response.data.city;
$scope.description_office = response.data.description;
$scope.showOfficeRegister = true;
}, function(response) {
$scope.showOfficeRegister = false;
build_error_message($scope, response, $timeout)
});
};