这是我的代码
var filter1 = { id: 96, name: "Affinity Groups Allowed In Site",typeId: 74, description: "SiteAffinityGroupsAllowed" };
var filter2 = { id: 125, name: "AffinityLob", typeId: 100, description: "AffinityLob" };
$scope.filterCriteriaObjets = [filter1, filter2];
我正在尝试使用ng-model获取名称,但似乎ng模型正在获取整个对象。这是我的下拉列表
<select class="form-control" name="role" ng model="filterCriteria.ObjectName"
ng-options="item as item.name for item in filterCriteriaObjets" ng-required="true" ng-change="getObjectInfo()">
<option value="">- Select Filter Name -</option>
</select>
但是当我更改选项filterCriteria.ObjectName时,获取整个对象。我希望ng-model只等于name属性
答案 0 :(得分:2)
这是你可以做的......
list = ['-1','2','+']
result=[]
for i in list:
if '-' in i:
result.append(i.replace('-','').isdigit())
else:
result.append(i.isdigit())
答案 1 :(得分:0)
您的错误声明ng-model
您将其声明为ng model
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.4.12/angular.js" data-semver="1.4.9"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<p>Hello {{name}}!</p>
<select class="form-control" name="role" ng-model="filterCriteria.ObjectName"
ng-options="item.name as item.name for item in filterCriteriaObjets" ng-required="true" ng-change="getObjectInfo()">
<option value="">- Select Filter Name -</option>
</select>
</body>
<script>
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
var filter1 = { id: 96, name: "Affinity Groups Allowed In Site",typeId: 74, description: "SiteAffinityGroupsAllowed" };
var filter2 = { id: 125, name: "AffinityLob", typeId: 100, description: "AffinityLob" };
$scope.filterCriteriaObjets = [filter1, filter2];
});
</script>
</html>
&#13;