从数据库角度JS下拉列表MVC获取数据时无法设置值 [英] Unable to set the value when getting data from database angular JS dropdownlist MVC
本文介绍了从数据库角度JS下拉列表MVC获取数据时无法设置值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法使用mvc和rest api设置角度下拉列表的值。
步骤:
1.打开列表页面并选择一条记录
2.导航到另一个页面,我可以编辑所选记录。
问题:
当我导航到页面(编辑页面)第一次没有设置下拉值
当我再次返回列表页面并选择记录然后选择下拉值。
i我无法理解什么是错了吗?
我尝试过:
HTML code :
I am unable to set the value of angular dropdownlist using mvc and rest api.
steps:
1. open the list page and select a record
2. navigate to another page where i can edit the selected record.
Issue:
when i navigate to page(edit page) 1st time the dropdown value is not set
when i go back to list page again and select record then dropdown value selected.
i am unable to understand what was wrong with it?
What I have tried:
HTML code:
<select ng-model="vm.CountryID">
<option ng-repeat="x in vm.country" value="{{x.countryID}}" ng-selected="{{x.countryID ==vm.CountryID}}" >{{x.countryName}}</option>
</select>
JS代码:
JS Code:
this.initializeController = function () {
vm.title = "Customer Maintenance";
vm.messageBox = "";
vm.alerts = [];
var city = new Object();
ajaxService.ajaxPost(city, "api/CityService/GetCity", this.getCityOnSuccess, this.getCityOnError);
var country = new Object();
ajaxService.ajaxPost(country, "api/CountryService/GetCountry", this.getCountryOnSuccess, this.getCountryOnError);
var customerID = ($routeParams.id || "");
if (customerID === "") {
vm.customerID = "0";
vm.customerName = "";
vm.customerAddress = "";
vm.CountryID = "1";
vm.CityID = "1";
vm.phoneNo = "(+92) 300-8888888";
}
else {
vm.customerID = customerID;
var customer = new Object();
customer.customerID = customerID;
ajaxService.ajaxPost(customer, "api/CustomerService/GetCustomer", this.getCustomerOnSuccess, this.getCustomerOnError);
}
};
this.getCustomerOnSuccess = function (response) {
vm.customerName = response.customerName;
vm.customerAddress = response.customerAddress;
vm.CityID = response.cityID;
vm.CountryID = response.countryID;
vm.phoneNo = response.phoneNo;
};
this.getCountryOnSuccess = function (response) {
vm.country = response.countries;
};
推荐答案
routeParams.id || );
if(customerID ===){
vm.customerID =0;
vm.customerName =;
vm.customerAddress =;
vm.CountryID =1;
vm.CityID =1;
vm.phoneNo =(+92)300-8888888;
}
else {
vm.customerID = customerID;
var customer = new Object();
customer.customerID = customerID;
ajaxService.ajaxPost(customer,api / CustomerService / GetCustomer,this.getCustomerOnSuccess,this.getCustomerOnError);
}
};
routeParams.id || ""); if (customerID === "") { vm.customerID = "0"; vm.customerName = ""; vm.customerAddress = ""; vm.CountryID = "1"; vm.CityID = "1"; vm.phoneNo = "(+92) 300-8888888"; } else { vm.customerID = customerID; var customer = new Object(); customer.customerID = customerID; ajaxService.ajaxPost(customer, "api/CustomerService/GetCustomer", this.getCustomerOnSuccess, this.getCustomerOnError); } };
this.getCustomerOnSuccess = function (response) {
vm.customerName = response.customerName;
vm.customerAddress = response.customerAddress;
vm.CityID = response.cityID;
vm.CountryID = response.countryID;
vm.phoneNo = response.phoneNo;
};
this.getCountryOnSuccess = function (response) {
vm.country = response.countries;
};
这篇关于从数据库角度JS下拉列表MVC获取数据时无法设置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文