我已经构建了一个函数,当最后一行获得焦点时,该函数会正确地将新行添加到表中。
这可以成功运行,但该指令不再触发克隆行 如何修复克隆,以便添加附加指令的元素。
克隆完成后,我需要触发指令 link
。
每一行都附有一个指令。
<tr add-table-row-empty>
<td>...
这是指令。
module Panda {
@directive('$log', '$compile')
export class AddTableRowEmpty implements ng.IDirective
{
public restrict: string = "A";
constructor(public $log: ng.ILogService, public $compile: ng.ICompileService)
{
}
public link: Function = ($scope: any, element: angular.IAugmentedJQuery, attrs: angular.IAttributes) => {
var inputs = $('input', element);
inputs.on('focus', () => this.addIfLastRow(element));
}
private addIfLastRow(element: angular.IAugmentedJQuery) {
if (!($(element).is(':last-child')))
return;
this.addRow(element);
}
private addRow(element: angular.IAugmentedJQuery)
{
// this should do a deep clone including all events etc.
var clone = element.clone(true, true);
$("input", clone).each((i, _) => $(_).val(""));
element.after(clone);
clone
.hide()
.fadeIn(1000);
}
}
panda.directive("addTableRowEmpty", <any>AddTableRowEmpty);
}