<tr ng-show="show">
<td>
<select class="form-control" data-ng-model="MyModel.FirstName" data-ng-options="firstname.Name for name in MyProperties" ng-show="editmode" style="width:100%; ">
<option value="" style="margin-left:25px">-Select First Name-</option>
</select>
</td>
<td>
<select class="form-control" data-ng-model="MyModel.LastName.SelectedOption" ng-options="lastname.Name for lastname in MyModel.LastName.Options" ng-show="editmode" style="width:100%; ">
<option value="" style="margin-left:25px">-Select Last Name-</option>
</select>
</td>
<td>
<a href="" class="glyphicon glyphicon-save buttons" data-placement="left" ng-click="editmode=!editmode;Save("Need to pass model which contain both above values")" ng-show="editmode"></a>
</td>
如何在单个模型中同时获取下拉(动态生成)值,我可以传递给save方法并在索引中获取它,js
index.js
$scope.Save = function (MyModel) {
var AlldataObj = {
FirstName: MyModel.FirstName,
LastName: MyModel.LasttName
};
答案 0 :(得分:1)
看看这段代码可能对你有用
<doctype html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
</head>
<body ng-app="myApp" data-ng-controller="HomeCtrl">
<select ng-model="opt.first" ng-options="obj.code as obj.code for obj in opts">
<option value="">select</option>
</select>
<select ng-model="opt.second" ng-options= "obj.code as obj.code for obj in opts1">
<option value="">select</option>
</select>
<button ng-click="save(opt)">Save</button>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script>
angular.module('myApp', []);
angular.module('myApp').controller('HomeCtrl', ['$scope', function($scope) {
$scope.opts = [
{
"code" : "ABC",
"num" : ["246810","4681012","681012"]
},
{
"code" : "DEF",
"num" : ["13579","357913","5791315"]
}
] ;
$scope.opts1 = [
{
"code" : "ABC",
"num" : ["246810","4681012","681012"]
},
{
"code" : "DEF",
"num" : ["13579","357913","5791315"]
}
] ;
$scope.save=function(model)
{
console.log("model==", model)
var obj={};
obj.firstname=model.first;
obj.lastname=model.second;
console.log("first==", obj.firstname);
console.log("last==", obj.lastname)
}
}]);
</script>
</body>
</html>
答案 1 :(得分:1)
在你的模型中似乎存在一些卷积,我猜这些卷曲形成了应用需求,这在这里并不明显。但是,我相信您的问题的主要答案是您可以在函数中定义模型:[r]-(n2)
其中ng-click="Save(MyModel)"
是MyModel
变量。
$scope
此外,您可以在保存功能中操作此信息:
<a href="javascript:void(0);" ng-click="editMode=!editMode;Save(MyModel)">Save</a>
我创建了一个有效的Plunkr作为参考here。