我正在添加聚合物元素。我想在单击其(自己的)图像时删除元素(自我)。根据封装,我将不得不让 parent 删除 child 。但这也需要为母体生成聚合物元素(我在这里吗??)。 children.add 没有为聚合物元素定义。我该怎么做,我计划在将聚合物元素添加到表单之前做一些检查。
已经阅读:
How to remove a child component with a delete button in the child itself
How do I fire a custom event from Polymer Dart?
How do you dispatch and listen for custom events in Polymer?
我通过调度事件传递什么?
初始化项目.html
<polymer-element name="init-item" >
<template>
<input type="image" src="button_minus_red.gif" on-click="{{remove}}" width = "15" height ="15">
{{Name}}<br>
</template>
<script type="application/dart" src="init-item.dart"></script>
</polymer-element>
初始化项目.dart
@HtmlImport('init-item.html')
import 'dart:html';
import 'dart:async';
import 'package:polymer/polymer.dart';
@CustomTag('init-item')
class PItem extends PolymerElement{
@observable String Name='hello';
void remove(){
Name='';
}
所以目前在单击图像时,名称属性会被重置。但这仅发生在从 main.dart 生成的后续点击事件上。这是由于数据绑定(bind)。我如何启动双向数据绑定(bind)。??
main.html(聚合物标签 不是 尽管有建议,但还是添加了。想不通)
...
<form id="youritems">
</form>
...
聚合物项目添加到上述标签。
主要.dart
...
main() async{
.. initPolymer().then((_) {});
}
..
...{..
var input = new InputElement(type:"image");
input.onClick.listen((p){
p.preventDefault();
populateYourPlayers(teams[i]);
});
}
void populateItems(String name){
Polymer.onReady.then((_) {
var pl = new Element.tag('player-item');
pl.playerName = name;
yourPlayer.children.add(pl);
});
}
..
最佳答案
如果您从 remove
重命名单击处理程序例如 removeItem
那么您可以调用remove()
在处理程序中,它将起作用。
<input type="image" src="button_minus_red.gif" on-click="{{removeItem}}" width = "15" height ="15">
void removeItem(){
Name='';
remove(); // removes the init-item (self)
}
remove
是所有元素的现有方法。如果您命名自己的方法remove
您覆盖默认值 remove
方法和原来的不能再被调用(除了在你的元素中使用 super.remove();
)
关于dart - 去除 Dart 中的聚合物元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29577881/