我有一个表格和表格。我通过表格绑定表格,我能够做到这一点,但我担心的是我想更新表格中的任何字段,但它没有立即显示在表格中。它在表格中显示但刷新页面后。但我希望它必须是动态的。 表的代码和表单的绑定如下:
<form class="form form-horizontal" id="serviceactivityForm" data-bind="foreach:items" action="<?php echo $BASE;?>projects/service_activities" method="post">
<div class="span3">
<input type="hidden" id="data_actid" name="actid" data-bind="value: actid" />
<div class="control-group">
<label class="control-label labellocation">Subject</label>
<div class="controls">
<input type="text" id="subject" name="subject" class="inputmargin" data-bind='value: subject' title="Please Enter Subject" required="" style="width:150px"/></div>
</div>
<div class="control-group">
<label class="control-label labellocation">Location</label>
<div class="controls">
<input type="text" id="location" name="location" data-bind='value: location' class="inputmargin" style="width:150px"></div>
</div>
</form>
<form class="form" action="<?php echo $BASE;?>projects/service_activities">
<div class="datagrid span4">
<table class="table table-hover table-bordered selectable " style="width:450px;" id="service_activitiesTable">
<thead>
<tr>
<th>Subject</th>
<th>Location</th>
<th>Assigned</th>
</tr>
</thead>
<tbody data-bind="foreach: items" >
<tr data-bind="value:actid" id="service_activity">
<td data-bind="text:subject"></td>
<td data-bind="text:location"></td>
<td data-bind="text:techname"></td>
</tr>
</tbody>
</table>
</div>
</form>
<script type="text/javascript">
$(function () {
$("#service_activity").live('click', function () {
$.ajax({
type: 'POST',
url: root + "projects/service_activities?json",
data: { id: $(this).val() },
success: function (o) {
ko.applyBindings(new DynamicModel(o.service_activity), document.getElementById("serviceactivityForm"));
},
dataType: "json"
});
});
});
</script>
有没有办法做到这一点..
答案 0 :(得分:0)
您能展示您的视图模型和初始绑定代码吗?
猜测,这是因为您在保存时正在创建一个新的viewmodel,并且正在使用它来应用绑定。您应该绑定到一个可观察数组的items属性,并且您希望使用更新的值添加它,而不是覆盖它。