内容简介:Angularjs的ng-repeat是用来循环产生呈现数据。当我们需要在ng-repeat循环中呈现一系列Checkbox时,某些checkbox选项是默认选中的。Html程序:
Angularjs的ng-repeat是用来循环产生呈现数据。
当我们需要在ng-repeat循环中呈现一系列Checkbox时,某些checkbox选项是默认选中的。
在ASP.NET MVC程序中的Entity,准备一些数据:
public IEnumerable<Car> Cars()
{
return new List<Car>()
{
{new Car() { ID = 1, Name = "玛莎拉蒂",Selected=false }},
{new Car() { ID = 2, Name = "奔驰" ,Selected=false }},
{new Car() { ID = 3, Name = "宝马" ,Selected=true }},
{new Car() { ID = 4, Name = "保时捷",Selected=false }}
};
}
Source Code
在ASP.NET MVC的控制器中,准备一个方法。这个方法是读取Entity的数据,并为angularjs准备一个呼叫的方法:
public JsonResult GetCars()
{
CarEntity ce = new CarEntity();
var model = ce.Cars();
return Json(model, JsonRequestBehavior.AllowGet);
}
public ActionResult CheckBox_IsChecked()
{
return View();
}
Source Code
OK,下面我们开始我们真正的程序angularjs:
Html程序:
<div ng-app="PilotApp" ng-controller="CarCtrl">
<div ng-repeat="c in Cars">
<div>
<input type="checkbox" value="{{c.ID}}" ng-checked="{{c.Selected}}" />{{c.Name}}
</div>
</div>
</div>
Source Code
Angularjs程序:
var pilotApp = angular.module("PilotApp", []);
pilotApp.controller('CarCtrl', function ($scope, $http) {
var obj = {};
$http({
method: 'POST',
url: '/Car/GetCars',
dataType: 'json',
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
data: JSON.stringify(obj),
}).then(function (response) {
$scope.Cars = response.data;
});
});
Source Code
程序运行最终呈现的效果:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- JQuery选中select组件被选中的值方法
- JQuery选中select组件被选中的值方法
- android 中心区域选中图表 WheelChart
- python – Django检查是否选中了复选框
- Xshell 配置 鼠标选中即复制,右键即粘贴的功能
- 手撕一个让人 “欲罢不能” 的水波纹选中控件
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Game Engine Architecture, Second Edition
Jason Gregory / A K Peters/CRC Press / 2014-8-15 / USD 69.95
A 2010 CHOICE outstanding academic title, this updated book covers the theory and practice of game engine software development. It explains practical concepts and techniques used by real game studios,......一起来看看 《Game Engine Architecture, Second Edition》 这本书的介绍吧!