<div class="col-md-12" data-bind="ifnot: Role()">
<label> <input type="checkbox" data-bind="checked: isAppAdmin"> Application Administrator </label>
<label> <input type="checkbox" data-bind="checked: isBusSegmentAdmin"> Business Segment Administrator </label>
<label> <input type="checkbox" data-bind="checked: isRegionAdmin"> Region Administrator </label>
<label> <input type="checkbox" data-bind="checked: isDivisionAdmin"> Division Administrator </label>
<label> <input type="checkbox" data-bind="checked: isExecutiveAdmin"> Executive Administrator </label>
<label> <input type="checkbox" data-bind="checked: isUserAdmin"> Security Administrator </label>
<button data-bind="click: $root.create">Create</button>
</div>
function RoleViewModel() {
var self = this;
self.roleID = ko.observable("");
self.isAppAdmin = ko.observable(false);
self.isBusSegmentAdmin = ko.observable(false);
self.isRegionAdmin = ko.observable(false);
self.isDivisionAdmin = ko.observable(false);
self.isExecutiveAdmin = ko.observable(true);
self.isUserAdmin = ko.observable(false);
var Role = {
roleID: self.roleID,
isAppAdmin: self.isAppAdmin,
isBusSegmentAdmin: self.isBusSegmentAdmin,
isRegionAdmin: self.isRegionAdmin,
isDivisionAdmin: self.isDivisionAdmin,
isExecutiveAdmin: self.isExecutiveAdmin,
isUserAdmin: self.isUserAdmin
};
self.Role = ko.observable();
self.Roles = ko.observableArray();
self.create = function () {
alert(ko.toJSON(Role));
}
}
var viewModel = new RoleViewModel();
ko.applyBindings(viewModel);
输出应该是这样::::请帮帮我...... {“roleID”:“”,“isAppAdmin”:“fasle”,“isBusSegmentAdmin”:“fasle”,“isRegionAdmin”:“fasle”,“isDivisionAdmin”:“true”,“isExecutiveAdmin”:“true”}
答案 0 :(得分:0)
roleID
未被更改,因为您没有标签。
但是,如果您记录viewModel.isAppAdmin()
并切换该复选框,则可以看到它正在发生变化。
我在这里试了一下:http://jsfiddle.net/rhAtc/
答案 1 :(得分:0)
Opps我想知道我的复选框设计脚本的问题.... 我已将几个样式添加到复选框..它停止将已检查状态返回到knockout.js ...
$("input[type='checkbox'], input[type='radio']").iCheck({
checkboxClass: 'icheckbox_minimal',
radioClass: 'iradio_minimal'
});
感谢您的帮助......