ng2 德拉古拉和 Angular 管道
ng2 Dragula and Angular pipes
我有 table 个来自数据库的值,这些值是我用 Dragula 生成的 table。 table 行可以拖放,一切似乎都按设计工作。问题是我有一个自定义管道应用于每行中的三个单元格值,以将其数据库值更改为人类可读的值(即:'N' 到 'Normal' & 'O' 到'Off-line',等等)。当我应用管道时,table 加载并正确显示;管道按预期工作。但是,当我拖放时,在放置事件中 table 中断并且应用管道的值变为空白。
当我移除管道时,table 按预期运行,但这些值当然不是人类可读的。
我的 HTML 有 dragula 指令:
<tbody class='wrapper' dragula='RIDRAG' id="left">
<tr class='container' *ngFor="let ri of this.riRow; let i = index">
<td><img src="./assets/images/Hamburger_icon.svg.png" style="width: 15px; padding-left: 5px;"></td>
<td>{{i + 1}}</td>
<td>{{ri.ri}}</td>
<td>{{ri.classification}}</td>
<td>{{ri.type}}</td>
<td>{{ri.shd}}</td>
<td>
<app-edit-ri-row [noGroupFlag]="this.noGroupFlag || disabledCheck()" (editEmit)="receiveEditEmit($event)" [riRow]="ri"></app-edit-ri-row>
<button style="width:50%;" type="submit" name="delete" [disabled]="this.noGroupFlag || disabledCheck() === true"
class="btn btn-danger rounded-0" (click)="removeRiRow(i)">
<fa-icon [icon]="['fas', 'trash-alt']" size="med"></fa-icon>
</button>
</td>
</tr>
</tbody>
我的 ts 组件展示了我如何创建 dragula 实例并解析它 returns 给我的数据。
this.dragula.createGroup('RIDRAG', {
removeOnSpill: false,
revertOnSpill: true
});
this.subs.add(this.dragula.drop('RIDRAG')
.pipe(map(data => {
this.varX = [];
this._STRINGARRAY = [];
this._XARRAY = [];
this._CHILDREN = data.source.children;
this._xARRAY = Object.values(this._CHILDREN);
for (let item in this._RIARRAY) {
this._STRINGARRAY.push(this._RIARRAY[item].innerText);
}
let index: number = 0;
for (let item in this._STRINGARRAY) {
let tempString = this._STRINGARRAY[item].trim();
this._XARRAY.push(tempString.split('\t'));
}
for (let item = 0; item < this._XARRAY.length; item++) {
let _SINGLETON: object;
if (this._XARRAY[item][1]) {
this._VAR2 = this._XARRAY[item][1];
this._VAR3 = this._XARRAY[item][2];
this._VAR4 = this._XARRAY[item][3];
this._VAR5 = this._XARRAY[item][4];
_SINGLETON = {
var1: index + 1,
var2: this._VAR2,
var3: this._VAR3,
var4: this._VAR4,
var5: this._VAR5
};
index++;
this.bar.push(_SINGLETON);
}
}
this.foo.emit(this.riRow);
}))
.subscribe()
);
Dragula 可以使用 Angular 管道吗?
可以将 Angular 管道与 Dragula 一起使用。
需要注意的部分是 Angular 管道正在读取 Dragula 对象返回的数据,每次放置都会读取和转换该数据,因此放置事件发生时的数据状态是导致我具体错误。
我有 table 个来自数据库的值,这些值是我用 Dragula 生成的 table。 table 行可以拖放,一切似乎都按设计工作。问题是我有一个自定义管道应用于每行中的三个单元格值,以将其数据库值更改为人类可读的值(即:'N' 到 'Normal' & 'O' 到'Off-line',等等)。当我应用管道时,table 加载并正确显示;管道按预期工作。但是,当我拖放时,在放置事件中 table 中断并且应用管道的值变为空白。
当我移除管道时,table 按预期运行,但这些值当然不是人类可读的。
我的 HTML 有 dragula 指令:
<tbody class='wrapper' dragula='RIDRAG' id="left">
<tr class='container' *ngFor="let ri of this.riRow; let i = index">
<td><img src="./assets/images/Hamburger_icon.svg.png" style="width: 15px; padding-left: 5px;"></td>
<td>{{i + 1}}</td>
<td>{{ri.ri}}</td>
<td>{{ri.classification}}</td>
<td>{{ri.type}}</td>
<td>{{ri.shd}}</td>
<td>
<app-edit-ri-row [noGroupFlag]="this.noGroupFlag || disabledCheck()" (editEmit)="receiveEditEmit($event)" [riRow]="ri"></app-edit-ri-row>
<button style="width:50%;" type="submit" name="delete" [disabled]="this.noGroupFlag || disabledCheck() === true"
class="btn btn-danger rounded-0" (click)="removeRiRow(i)">
<fa-icon [icon]="['fas', 'trash-alt']" size="med"></fa-icon>
</button>
</td>
</tr>
</tbody>
我的 ts 组件展示了我如何创建 dragula 实例并解析它 returns 给我的数据。
this.dragula.createGroup('RIDRAG', {
removeOnSpill: false,
revertOnSpill: true
});
this.subs.add(this.dragula.drop('RIDRAG')
.pipe(map(data => {
this.varX = [];
this._STRINGARRAY = [];
this._XARRAY = [];
this._CHILDREN = data.source.children;
this._xARRAY = Object.values(this._CHILDREN);
for (let item in this._RIARRAY) {
this._STRINGARRAY.push(this._RIARRAY[item].innerText);
}
let index: number = 0;
for (let item in this._STRINGARRAY) {
let tempString = this._STRINGARRAY[item].trim();
this._XARRAY.push(tempString.split('\t'));
}
for (let item = 0; item < this._XARRAY.length; item++) {
let _SINGLETON: object;
if (this._XARRAY[item][1]) {
this._VAR2 = this._XARRAY[item][1];
this._VAR3 = this._XARRAY[item][2];
this._VAR4 = this._XARRAY[item][3];
this._VAR5 = this._XARRAY[item][4];
_SINGLETON = {
var1: index + 1,
var2: this._VAR2,
var3: this._VAR3,
var4: this._VAR4,
var5: this._VAR5
};
index++;
this.bar.push(_SINGLETON);
}
}
this.foo.emit(this.riRow);
}))
.subscribe()
);
Dragula 可以使用 Angular 管道吗?
可以将 Angular 管道与 Dragula 一起使用。 需要注意的部分是 Angular 管道正在读取 Dragula 对象返回的数据,每次放置都会读取和转换该数据,因此放置事件发生时的数据状态是导致我具体错误。