Dart Polymer 1.0-双向装订有效吗? [英] Dart Polymer 1.0 - Two-way binding works?

查看:66
本文介绍了Dart Polymer 1.0-双向装订有效吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Dart Polymer 1.0-RC2中双向绑定有效吗?

Two-way binding works in Dart Polymer 1.0 - RC2?

当我在.dart中更改字段@Property(nofity:true)时,它不会反映(更改)为.html中的{{}}。

When I change the field @Property(nofity: true) in the .dart, it does not reflect (change) into {{}} in the .html.

请参见以下示例。

Whem我单击纸按钮,将其触发 clicar ,更改了 text 属性,但 {{text}} 不变!

Whem I click on paper-button, it´s fire clicar, the property text is changed, but {{text}} does not change!

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";
  }
}


推荐答案

您需要使用提供的方法来更新属性,例如

You need to use the provided methods to updated properties like

 set('text', "super teste");

通知:true 仅用于通知家长元素(触发 test-changed 事件)

notify: true is only to notify parent elements (fires an test-changed event)

PolymerBase mixin,您可以通过扩展 PolymerElement 来自动添加,并通知Polymer有关更改。

There are quite a lot such methods in PolymerBase mixin which you get automatically added by extending PolymerElement and which notify Polymer about changes.


  • notifyPath (当前与 set 相同)

  • notifyPath (currently the same as set)

用于收集


  • 添加

  • addAll

  • 清除

  • fillRange

  • 插入

  • insertAll

  • removeItem

  • removeAt

  • removeLast

  • removeRange

  • removeWhere

  • replaceRange

  • retainWhere

  • s etAll

  • setRange

  • add
  • addAll
  • clear
  • fillRange
  • insert
  • insertAll
  • removeItem
  • removeAt
  • removeLast
  • removeRange
  • removeWhere
  • replaceRange
  • retainWhere
  • setAll
  • setRange

还有一个


  • get

  • get

不确定使用它的目的。

not sure about what to use it for.

这篇关于Dart Polymer 1.0-双向装订有效吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆