我有一個表中的值的列表與編輯按鈕使用knockout.js,當編輯按鈕被點擊時,我想列表上方的形式填充值來自表。我如何用我目前的淘汰賽視角模型做到這一點?從表中選擇與淘汰js的填充表格
這裏的HTML
<script src="~/scripts/appjs/GeneAssay.js"></script>
<script type="text/javascript">
$(function() {
//Dump raw data into one place
var data = @Html.Raw(ViewBag.Data);
//initialize view model
var viewModel = new ViewModel(data);
ko.applyBindings(viewModel);
});
</script>
<div class="row geneassayform">
<div class="col-md-4">
<form>
<div class="form-group">
<label for="form_geneassaycode">Gene Assay Code:</label>
<input type="text" class="form-control" id="form_geneassaycode" placeholder="Enter Gene Assay Code">
</div>
<div class="form-group">
<label for="form_geneassayname">Gene Assay Name:</label>
<input type="text" class="form-control" id="form_geneassayname" placeholder="Enter Gene Assay Name">
</div>
<div class="form-group">
<label for="form_geneassaycomments">Gene Assay Comments:</label>
<textarea class="form-control" id="form_geneassaycomments" placeholder="Enter Gene Assay Comments(optional)"></textarea>
</div>
<button type="submit" class="btn btn-primary" disabled="disabled">Save</button>
</form>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<span>Current Gene Assays</span>
</div>
<div class="panel-body">
<!-- ko if: Assays().length > 0 -->
<table class="table table-condensed table-hover">
<tr>
<th>Assay Code</th>
<th>Assay Name</th>
<th>Comments</th>
<th></th>
</tr>
<tbody>
<!-- ko foreach: Assays -->
<tr>
<td data-bind="text: AssayCode"></td>
<td data-bind="text: AssayName"></td>
<td data-bind="text: Comments"></td>
<td><button class="btn btn-xs btn-danger" data-bind="click: $parent.editAssay">edit</button></td>
</tr>
<!-- /ko -->
</tbody>
</table>
<!-- /ko -->
<!-- ko ifnot: Assays().length > 0 -->
<div class="alert alert-info">
<p>There are no Gene Assays. Add an Assay using the form above.</p>
</div>
<!-- /ko -->
</div>
</div>
</div>
這裏的GeneAssay.js
function ViewModel(data) {
var self = this;
//Unpack raw data
self.Assays = ko.mapping.fromJS(data.assays);
}
請發表您迄今爲止所做的一切嗎? –
@ebramtharwat上面的代碼是我迄今爲止所做的與工作結果的屏幕截圖..其他代碼,我試過我刪除,因爲應用程序不工作 – iambdot