0
我無法弄清楚如何讓我的Bootstrap模塊通過敲除數據綁定表示內容。如何使用敲除數據綁定來獲得Bootstrap模態?
關於下面的例子,我如何使shortName正確顯示在每個模態的主體中?
我有一個視圖模型:
function Stock(stockName) {
var self = this;
self.name = ko.observable(stockName);
self.shortName = ko.observable();
...
}
...
function StockViewModel() {
var self = this;
stock1 = new Stock('Facebook');
stock2 = new Stock('Twitter');
self.stockList = ko.observableArray([stock1, stock2]);
...
self.updateStockData = function() {
$.ajax({
url: "/stockShortName/" + self.name(),
type: "GET",
success: function(response) {
self.shortName(response);
}
});
}
}
ko.applyBindings(new StockViewModel());
在視圖中我有:
<table>
<thead>
<tr>
<th>Stock Name</th>
</tr>
</thead>
<tbody data-bind="foreach: stockList">
<tr>
<td>
<div data-bind="template: { name: 'stock-template', data: $data}"></div>
</td>
</tr>
</tbody>
</table>
<div class="modal fade" id="stock-detail-modal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-md" role="document">
<div class="modal-content">
<div class="modal-body">
<p>Here comes the body: ...</p>
<div data-bind="text: shortName"></div>
</div>
</div>
</div>
</div>
<script type="text/html" id="stock-template">
<a data-toggle="modal" href="#stock-detail-modal" id="1234">
<div data-bind="text: name"></div>
</a>
</script>
http://faulknercs.github.io/Knockstrap/#modal –