Dart Polymer 1.0 - RC2 中的双向绑定(bind)有效吗?
当我更改 .dart 中的字段 @Property(nofity: true) 时,它不会反射(reflect)(更改)到 .html 中的 {{}}。
请参阅以下示例。
当我点击纸张按钮时,它会触发clicar,属性text被更改,但是{{text}}没有改变!
main_app.html
<dom-module id="main-app">
<style>
:host {
display: block;
}
</style>
<template>
<paper-input label="Type something..." value="{{text}}"></paper-input>
<p>
Text: <span>{{text}}</span><br />
</p>
<paper-button on-click="clicar">cliqueme</paper-button>
</p>
</template>
</dom-module>
main_app.dart
@HtmlImport('main_app.html')
library untitled8.lib.main_app;
import 'dart:html';
import 'package:polymer_elements/paper_button.dart';
import 'package:polymer_elements/paper_input.dart';
import 'package:polymer/polymer.dart';
import 'package:web_components/web_components.dart';
@PolymerRegister('main-app')
class MainApp extends PolymerElement {
@Property(notify: true)
String text;
MainApp.created() : super.created();
@reflectable
void clicar(e, detail) {
text = "super teste";
}
}
最佳答案
您需要使用提供的方法来更新属性,例如
set('text', "super teste");
notify: true
仅通知父元素(触发 test-changed
事件)
在PolymerBase
mixin中有很多这样的方法,您可以通过扩展PolymerElement
来自动添加它们,并通知Polymer有关更改的信息。
notifyPath
(当前与set
相同)
对于集合有
添加
addAll
清除
填充范围
插入
插入全部
删除项目
removeAt
删除最后一个
删除范围
removeWhere
替换范围
retainWhere
setAll
设置范围
还有一个
获取
不知道用它做什么。
关于Dart Polymer 1.0 - 双向绑定(bind)有效吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33170456/