2013-01-24 45 views
0

我確實有一個表格和表格。我通過表格綁定表格,我能夠做到這一點,但我的關注點是我想更新表格中的任何字段,但它沒有立即顯示在表格中。它在表格中顯示,但在刷新頁面後顯示。但我希望那是必須的動態。 爲表和裝訂形式的代碼如下:動態顯示錶中的更新數據

<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> 

那麼,有沒有辦法做到這一點..

+1

請參閱http://stackoverflow.com/questions/12184199/how-to-update-an-array-table-dynamically-with-ajax-and-jquery –

回答

0

你能告訴您的視圖模型和inital綁定代碼?

有人猜測,這是因爲您在保存時正在創建新的視圖模型,並且正在使用該模型應用綁定。您應該綁定到一個可觀察數組的項目屬性,並且您想要使用更新的值添加它,而不是覆蓋它。