我知道有類似的問題,但我真的找不到適合我的問題的答案。爲什麼我不能在同一個表中使用兩次datepicker?
我有這個HTML
表女巫循環槽的陣列 - 在我的視圖模型定義:
<div class="formElement" id="AssimilationDT" style="overflow-x: auto; width: 100em;">
<table class="dataTable">
<thead>
<tr>
<th> 1 </th>
<th> 2 </th>
<th> 3</th>
<th> 4</th>
<th> 5</th>
<th> 6</th>
<th> 7</th>
<th> 8</th>
<th> 9</th>
<th> 10</th>
<th> 11</th>
<th> 12/th>
<th> 13</th>
<th> 14</th>
<th> 15</th>
<th> 16</th>
<th></th>
</tr>
</thead>
<tbody data-bind="foreach: assimilationRows">
<tr>
<td><input type="text" name="AssimilationDate" id="AssimilationDate" data-bind="event: { mouseover: assimilationDatePicker}, value: AssimilationDate"></td>
<td><input type="text" name="InvoiceSum" data-bind="value: InvoiceSum"></td>
<td><input type="text" name="FondAssimAmm" data-bind="value: FondAssimAmm"></td>
<td><input type="text" name="FondSgebFondPerc" data-bind="value: FondSgebFondPerc"></td>
<td><input type="text" name="FondWholeAssimPerc" data-bind="value: FondWholeAssimPerc"></td>
<td><input type="text" name="SgebAssimAmm" data-bind="value: SgebAssimAmm"></td>
<td><input type="text" name="SgebFondSgeb" data-bind="value: SgebFondSgeb"></td>
<td><input type="text" name="SgebWholeAssimPerc" data-bind="value: SgebWholeAssimPerc"></td>
<td><input type="text" name="FondSuppl" data-bind="value: FondSuppl"></td>
<td><input type="text" name="FondSupplNum" data-bind="value: FondSupplNum"></td>
<td><input type="text" name="FondSupplInvNum" data-bind="value: FondSupplInvNum"></td>
<td><input type="text" name="FondDesc" data-bind="value: FondDesc"></td>
<td><input type="text" name="SgebSuppl" data-bind="value: SgebSuppl"></td>
<td><input type="text" name="SgebSupplNum" data-bind="value: SgebSupplNum"></td>
<td><input type="text" name="SgebSupplInvNum" data-bind="value: SgebSupplInvNum"></td>
<td>
<img src="/HDSHubCreditMonitoring/js/images/close.jpg" alt="Close" data-bind="click: $root.removeAssimilationRow">
</td>
</tr>
</tbody>
</table>
<button type="button" id="newSupplierRow" class="button" data-bind="click: newAssimilationRow">Добави Ред</button>
</div>
什麼我在我的視圖模型是下面的代碼 - 包含錶行,它應該執行.datepicker
:
AssimilationInfo = function(clientNum){
this.AssimilationDate = null;
this.InvoiceSum = null;
this.FondAssimAmm = null;
this.FondSgebFondPerc = null;
this.FondWholeAssimPerc = null;
this.SgebAssimAmm = null;
this.SgebFondSgeb = null;
this.SgebWholeAssimPerc = null;
this.FondSuppl = null;
this.FondSupplNum = null;
this.FondSupplInvNum = null;
this.FondDesc = null;
this.SgebSuppl = null;
this.SgebSupplNum = null;
this.SgebSupplInvNum = null;
this.SgebDesc = null;
assimilationDatePicker = (function() {
$("#AssimilationDate").datepicker({
yearRange: "-20:+100",
changeMonth: true,
changeYear: true,
dateFormat: "d-M-y"
});
});
},
和
newAssimilationRow = function(){
this.assimilationRows.push(new AssimilationInfo(this.clientNumber()));
},
removeAssimilationRow = function (ca){
assimilationRows.remove(ca);
},
上述函數正在添加或刪除HTML表中的行。 我面臨的問題是.datepicker
只適用於第一個表格行 - 如果我添加另一行,它只是不工作。
我很確定我無法正確調用它,但我無法將該問題作爲初學者發現。有沒有辦法在每個表格行上調用datepicker
?
UPDATE
我加
assimilationDatePicker = (function() {
$(".AssimilationDate").datepicker({
yearRange: "-20:+100",
changeMonth: true,
changeYear: true,
dateFormat: "d-M-y"
});
});
,現在它顯示了每一行,但只有第一排輸入的值更新。
因爲你爲id創建datepicker:'$ text「name =」AssimilationDate「id =」AssimilationDate「class =」AssimilationDate「data-bind =」event:{mouseover:assimilationDatePicker},value:AssimilationDate「>' – krasu
@krasu它的工作,但現在它只更新第一個框的值:( – Slim
'assimilationDatePicker = ...' - 是全局對象,試試這個'this.assimilationDatePicker = ...',我沒有knockout.js的專業知識,所以不確定它會幫助 – krasu