我想創建自定義模態。基本上,我有一個表中有行。當用戶點擊一行時,我想要一個彈出窗口出現。我正在描述如何在此鏈接中創建自定義模態:http://durandaljs.com/documentation/Showing-Message-Boxes-And-Modals/在點擊表格行時顯示自定義模式
根據描述,我想我需要兩個類來創建自定義模態。一個是觀點,另一個是模態。
我其實在鏈接中的代碼完全相同的兩個類。
我的問題是,如何在單擊行時顯示自定義模式?
比方說,這是我在我看來表改名index.html
<table class="table table-bordered table-hover">
<thead>
<tr>
<th></th>
<th>Item</th>
<th>Price</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
並假設我有一個名爲messageBox.html
視圖下面是它的代碼:
<div class="messageBox">
<div class="modal-header">
<h3 data-bind="html: title"></h3>
</div>
<div class="modal-body">
<p class="message" data-bind="html: message"></p>
</div>
<div class="modal-footer" data-bind="foreach: options">
<button class="btn" data-bind="click: function() { $parent.selectOption($data); }, html: $data, css: { 'btn-primary': $index() == 0, autofocus: $index() == 0 }"></button>
</div>
</div>
和被叫messageBox.js
模式。下面是它的代碼:
define(function() {
var MessageBox = function(message, title, options) {
this.message = message;
this.title = title || MessageBox.defaultTitle;
this.options = options || MessageBox.defaultOptions;
};
MessageBox.prototype.selectOption = function (dialogResult) {
this.modal.close(dialogResult);
};
MessageBox.defaultTitle = '';
MessageBox.defaultOptions = ['Ok'];
return MessageBox;
});
如何將表單擊事件與我創建的這個自定義模式綁定?
我認爲如果您提供相關的代碼而不是讓其他人去找它,您將有更好的機會獲得幫助。 – ultranaut 2013-03-23 20:39:57
我明白了,讓我編輯我的帖子。 – Stranger 2013-03-23 20:45:19