Angularjs 在ng repeat和ng change中传递两个值
控制器:Angularjs 在ng repeat和ng change中传递两个值,angularjs,angularjs-ng-repeat,angularjs-ng-change,Angularjs,Angularjs Ng Repeat,Angularjs Ng Change,控制器: var response = { "json": { "response": { "servicetype": "100", "functiontype": "101", "statuscode": "success", "data": [ { "countryid": 1, "countryname": "India", "countrycode":
var response = {
"json": {
"response": {
"servicetype": "100",
"functiontype": "101",
"statuscode": "success",
"data": [
{
"countryid": 1,
"countryname": "India",
"countrycode": "91",
"currencyname": "Indian rupee",
"currencycode": "INR",
"latitude": "21.7679",
"longitude": "78.8718"
}
]
}
}
}
$scope.country = response.json.response.data;
Html:
国家*
{{item.countryname}
我想传递countryname和countryid来获取州列表,需要解决方案。我只能通过国家/地区id。需要帮助。使用
ng选项
:
<select ng-model="model.country" required
ng-options="c.countryid as c.countryname for c in country" >
<option value="">Country*</option>
</select>
国家*
它将为您提供以下输出:
<select ng-model="model.country" required=""
ng-options="c.countryid as c.countryname for c in country"
class="ng-pristine ng-invalid ng-invalid-required">
<option value="" class="">Country*</option>
<option value="0">India</option>
</select>
国家*
印度
关于您的案例:
track by$index
是打破您的select
国家*
使用
ng选项
,您将获得国家/地区模型中的所有值,因此您希望在ng更改中传递两个内容?这不起作用吗:ng change=“getState(model.country,model.id)”?model.id呢?我们如何分配它在最后一个错误。好的,那么getState()是控制器上的一个方法,对吗?传入的model.country应该是您在下拉列表中选择的模型,因此如果您想要countryname/CountryId,则getState()应该具有所需的所有内容,但我的问题是关于ng更改以及您的答案中缺少的内容。你能帮我通过countryid和CountryName更改对我不起作用吗。getState(item.id,item.country)我得到了未定义的值。你能传递getState(country)吗?请检查你的型号名称,如果是国家更改为'item'
<select ng-model="model.country" required=""
ng-options="c.countryid as c.countryname for c in country"
class="ng-pristine ng-invalid ng-invalid-required">
<option value="" class="">Country*</option>
<option value="0">India</option>
</select>
<select ng-model="country" required
ng-options="c as c.countryname for c in country track by c.countryid" ng-change="getState(country.countryid, country.countryname);" >
<option value="">Country*</option>
</select>