创建这些文件
1-mobiles.html
<!DOCTYPE html>
<head>
<title>Learning AngularJS</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js" type="text/javascript"></script>
<script src="app.js" type="text/javascript"></script>
<script src="maincontroller2.js" type="text/javascript"></script>
<style>
.odd{
background:#FFFFCC;
}
.even{
background:#CCCCCC;
}
tr th{
background:#666666;
color:#FFF;
}
</style>
</head>
<body>
<div id='content' ng-app='MyTutorialApp' ng-controller='MainController'>
Select:
<select ng-model='selectedMobile'>
<option ng-repeat='mobile in mobiles' value="{{mobile.id}}">{{mobile.name}}</option>
</select>
Search:
<input type='text' ng-model='searchText' />
<table width="335px" frame="box" rules="all">
<tr>
<th>ID</th><th>Model</th><th>Price</th>
</tr>
<tr ng-repeat="label in mobiles[selectedMobile].models | filter:searchText" ng-class-odd="'odd'" ng-class-even="'even'">
<td>{{label.id}}</td>
<td>{{label.model}}</td>
<td>{{label.price}}</td>
</tr>
<tr>
<td><button ng-click='addNew()'>Add</button></td>
<td><input type='text' size="10" ng-model='newModel' /></td>
<td><input type='text' size="10" ng-model='newprice' /></td>
</tr>
</table>
<p>{{(mobiles[selectedMobile].models | filter:searchText).length+0 }} record(s) found.</p>
</div>
</body>
</html>
2-maincontroller.js
var app = angular.module('MyTutorialApp',[]);
app.controller("MainController", function($scope){
$scope.newModel = null;
$scope.newPrice = null;
$scope.addNew = function() {
if ($scope.newModel != null && $scope.newModel != "" && $scope.newPrice != null && $scope.newPrice != "") {
$scope.mobiles.push({
id : $scope.mobiles.length,
name: $scope.newModel,
//price: $scope.newPrice,
models:[]
});
}
}
$scope.mobiles=[
{
id: 0,
name: 'nokia',
models: [
{
id:0,
model:'6600',
price:2000
},
{
id:1,
model:'6610',
price:2100
},
{
id:2,
model:'6300',
price:2500
},
{
id:3,
model:'7610',
price:4100
},
{
id:4,
model:'7620',
price:4500
}
]
},
{
id: 1,
name: 'Samsung',
models: [
{
id:0,
model:'s1',
price:2000
},
{
id:1,
model:'s1.1',
price:2100
},
{
id:2,
model:'s2',
price:2500
},
{
id:3,
model:'s2 mini',
price:4100
},
{
id:4,
model:'S3',
price:4500
}
]
},
{
id: 2,
name: 'iPhone',
models: [
{
id:0,
model:'iphone 3',
price:2000
},
{
id:1,
model:'iphone 4',
price:2100
},
{
id:2,
model:'ipphone 5',
price:2500
},
{
id:3,
model:'iphone 6',
price:4100
},
{
id:4,
model:'iphone 7',
price:4500
}
]
}
];
});
这有你需要的一切,甚至更多....
比如返回的记录
和行替代着色