【发布时间】:2015-07-16 17:33:47
【问题描述】:
我有一个带有一些模型的自定义元素。这是自定义元素的代码。
message-element.html
<polymer-element name="message-element" attributes="message">
<template>
<table class="table">
<tr template repeat="{{attrib in attribs}}">
<td><paper-input name="message-attrib-name" label="New Attribute" value="{{attrib.name}}"></paper-input></td>
<td>
<paper-input name="message-attrib-value" label="" value="{{attrib.value}}"></paper-input>
<core-icon-button icon="check" on-tap="{{addAttribute}}"></core-icon-button>
<core-icon-button icon="highlight-remove" on-tap="{{deleteAttribute}}"></core-icon-button>
</td>
</tr>
</table>
</template>
<script type="application/dart" src="message-element.dart"></script>
</polymer-element>
message-element.dart
@CustomTag('message-element')
class MessageElement extends PolymerElement with Observable {
@published Message message;
@observable List<Attribute> attribs = toObservable([]);
@observable Attribute att;
/// Constructor used to create instance of MainApp.
MessageElement.created() : super.created() {
polymerCreated();
}
attached() {
att = new Attribute('', '');
attribs.add(att);
message.attributes = attribs; // initialize with 1 attrib
}
void addAttribute(Event event, Object detail, Node sender) {
att = new Attribute('', '');
attribs.add(att);
}
void deleteAttribute(Event event, Object detail, Node sender) {
// remove the clicked attrib
}
}
attribs 显示在模态对话框中,attribs 中的每个属性都有一对带有添加和删除按钮的输入。添加元素工作正常。如何从属性中删除单击的属性。我在点击删除按钮时调用 void deleteAttribute(Event event, Object detail, Node sender)。在此调用中,我需要从列表中删除属性,但如何获取点击属性的详细信息,以便我可以从列表中删除它。
【问题讨论】:
标签: data-binding dart polymer dart-polymer