Angularjs 如何创建ng模型数组
我正在使用angularJs开发网站。在应用程序中,我需要创建具有相同型号名称的动态选择框。代码如下所示 HTML代码 json响应 这里每个域名都有多个价格,我面临的问题是,我无法在模型中得到价格的价值Angularjs 如何创建ng模型数组,angularjs,Angularjs,我正在使用angularJs开发网站。在应用程序中,我需要创建具有相同型号名称的动态选择框。代码如下所示 HTML代码 json响应 这里每个域名都有多个价格,我面临的问题是,我无法在模型中得到价格的价值 请任何人帮我解决这个问题问题是你需要反复查看记录,而不是价格 类似的方法可能会奏效: <select ng-model="myPrice" class="form-control" name="price" ng-options="record.price.dp_id as record
请任何人帮我解决这个问题问题是你需要反复查看记录,而不是价格 类似的方法可能会奏效:
<select ng-model="myPrice" class="form-control" name="price" ng-options="record.price.dp_id as record.price.title for record in results">
<option value="">-- choose price --</option>
</select>
官方的例子可能会有所帮助,谢谢你的建议。我所做的是正确的,但我犯了一个愚蠢的错误,我在值和json响应中使用了dm_id。ng options=record.price.dp_id作为结果中记录的record.price.title。很高兴您能使用它。最好的办法是把它作为一个答案,并接受它。
app.controller("Site", function($scope,$http) {
$scope.selectedPerson = 0;
$scope.urlName = "alankar12";
$scope.domainExt = "";
$scope.showresult=false;
$scope.result = {};
$scope.price=[];
$scope.checkDomain = function() {
$http({
method: 'POST',
url: 'http://localhost/domain/index.php?r=site/checkdomain',
data:{urlName:$scope.urlName,domainExt:$scope.domainExt},
}).success(function(data, status, headers, config) {
$scope.domainExt=data;
$scope.result=data.records;
$scope.showresult=true;
//$scope.price=data.price;
console.log(data.price);
}).error(function(data, status, headers, config) {
});
}; //end checkdomain Function
$scope.addDomain = function() {
console.log($scope.price);
}
});
{
"response": "successful",
"status": "200",
"records": [{
"domain": ".com",
"status": "available",
"price": [{
"title": "1 year@600",
"price": "600.00"
}, {
"title": "2 year @1150",
"price": "1150.00"
}]
}, {
"domain": ".co.in",
"status": "available",
"price": [{
"title": "1 year@700",
"price": "700.00"
}, {
"title": "2 year @1350",
"price": "1350.00"
}]
}, {
"domain": ".in",
"status": "available",
"price": [{
"title": "1 year@660",
"price": "660.00"
}, {
"title": "2 year @1350",
"price": "1350.00"
}]
}, {
"domain": ".org",
"status": "available",
"price": [{
"title": "1 year@500",
"price": "500.00"
}]
}, {
"domain": ".au.in",
"status": "available",
"price": [{
"title": "1 year 600",
"price": "600.00"
}]
}, {
"domain": ".au",
"status": "available",
"price": [{
"title": "1 year@500",
"price": "500.00"
}]
}]
}
<select ng-model="myPrice" class="form-control" name="price" ng-options="record.price.dp_id as record.price.title for record in results">
<option value="">-- choose price --</option>
</select>
var allPrices = [];
results.each(function(result) {
result.price.each(function(price) {
// gather all prices here
}
}
$scope.prices = allPrices;