Databinding of polymer paper_input does not work

两盒软妹~` 提交于 2019-12-20 03:26:09

问题


I have the following code where a 2-way binding is expected between first_name and the property val.

  <!DOCTYPE html>

  <link rel="import" href="packages/polymer/polymer.html">

  <link rel="import" href="packages/paper_elements/paper_input.html" >

  <polymer-element name='paper-input-snippet'>
    <template>

    <div on-mouseout="{{zoom}}">
      <paper-input
        label="First" floatinglabel
        error="Invalid input"

        id="first_name"
        value='{{val}}'>
      </paper-input>

      <paper-input
        label="Middle" floatinglabel
        error="Invalid input"

        id="middle_name">
      </paper-input>

      <paper-input
        label="Last" floatinglabel
        error="Invalid input"

        id="last_name">
      </paper-input>

    </div>

    </template>

    <script type="application/dart">

    import 'package:polymer/polymer.dart';
    import 'dart:html';

    import 'package:paper_elements/paper_input.dart';

    @CustomTag( 'paper-input-snippet' )
    class PaperInputSnippet extends PolymerElement
    {
      @observable String val = 'Tommy';
      String receiver = '';

      PaperInputSnippet.created() : super.created();

      void zoom( Event e, var detail )
      {
        print ( e.target );
        print ( val);
      }

      @override
      void attached()
      {
         super.attached();
         receiver = this.dataset['receiver'];
      }
    }

    </script>
  </polymer-element>

However, changing the value of the paper-element does not print the new value, only the intialized value is printed.

Is this a bug or am I doing something wrong>


回答1:


EDIT

An updated Polymer packages was just published that should fix this issue see https://groups.google.com/a/dartlang.org/forum/#!topic/bugs/-2f-TeaOoac for more details.

You need to adjust your dependency constraint to get this update because its a development release

polymer: ">= 0.11.1-dev < 0.12.0" 

EDIT END

There is an open issue for this code.google.com/p/dart/issues/detail?id=19794

Until it is fixed, you can work around it by adding an on-change event handler:

<paper-input
    label="First" floatinglabel
    error="Invalid input"

    id="first_name"
    value='{{val}}'
    on-change='{{firstNameChangeHandler}}'
    >
  </paper-input>
  void firstNameChangeHandler() {
    val = ($['first_name'] as PaperInput).value;
  }


来源:https://stackoverflow.com/questions/24601866/databinding-of-polymer-paper-input-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!