87,984
社区成员
发帖
与我相关
我的任务
分享 <script type="text/javascript">
function ViewModel(options) {
var sss = [{ id: '11',name:'name1' }, { id: '22',name:'name2'}]
var self = this;
self.sbs = ko.observableArray({
id: ko.observable(),
name: ko.observable()
};);
self.replacedata = function (data) {
for (var i = 0; i < self.sbs().length; i++) {
var existing = self.sbs()[i];
if (existing.id == data.id) {
self.sbs.replace(existing, data);
}
}
}
}
Object.prototype.clone = function () {
var obj = {};
for (var p in this)
obj[p] = this[p];
return obj;
};
$(function () {
$("#Button1").click(function () {
$.each(viewModel.sbs(), function (n, value) {
existing = value;
if (value.id == '11') {
value.name = "1212";
viewModel.sbs.replace(existing, value);
//return false;
}
});
});
ko.applyBindings(viewModel);
});
</script>
</head>
<body>
<form id="form1" runat="server">
<input id="Button1" type="button" value="button" />
<table>
<thead>
<tr>
<th>
</th>
<th>
检查项目
</th>
<th>
检查结果
</th>
<th>
判定
</th>
</tr>
</thead>
<tbody data-bind='foreach: sbs'>
<tr>
<td>
<input type="text" data-bind="value: name" />
</td>
</tr>
</tbody>
</table>
</form>
</body>
<ml>
