アプリケーションを0.5からDartを使用してポリマー1に移行します。私は大丈夫でしたが、今ではいくつかのデータバインディングの問題に直面しています:データバインディング構造化オブジェクトは、ポリマー要素に変更を表示しません
連絡先の情報を与える別のポリマー要素をローカルDOMにプログラム的に挿入するポリマー要素を作成しました。 2番目の要素はコンストラクタから情報を取得し、データバインディングを介してインタフェースに表示します。
親ダーツ:
@PolymerRegister('test-app')
class TestApp extends PolymerElement {
TestApp.created() : super.created();
attached() {
super.attached();
async(() {
insertTile();
});
}
void insertTile() {
String contactJSON = '{"contactId":"1", "firstName":"Lex", "surname":"Luthor"}';
Contact contact = new Contact(JSON.decode(contactJSON));
ContactTile tile = new ContactTile(contact, this);
Polymer.dom(this.root).append(tile);
}
}
親HTML:
<dom-module id="test-app">
<style>
:host {
display: block;
}
</style>
<template>
</template>
</dom-module>
子供ダーツ:
@PolymerRegister('contact-tile')
class ContactTile extends PolymerElement {
factory ContactTile(Contact contact, Element parent) {
ContactTile tile = new Element.tag('contact-tile');
tile.contact = contact;
return tile;
}
ContactTile.created() : super.created();
@property Contact contact;
}
子供のhtml:
<dom-module id="contact-tile">
<style>
:host {
display: block;
}
</style>
<template>
<div>{{ contact.contactId }}</div>
<div>{{ contact.firstName }}</div>
<div>{{ contact.surname }}</div>
</template>
</dom-module>
Contactクラス:
class Contact {
String contactId;
String firstName;
String surname;
Contact(Map map) {
contactId = map['contactId'];
firstName = map['firstName'];
surname = map['surname'];
}
}
接触がコンストラクタに更新された後、データバインディングは、Webインターフェイス上の連絡先の属性のいずれかを示していないいくつかの理由。誰も私にこれを手伝うことができますか?私はこれをPolymer 0.5について何度もやってきましたが、Polymer 1ではこれはうまくいきません。
ありがとうございました。問題は、通知に関連していた
==============================
SOLUTION ContactTileのコンストラクタで生成されません。私はプロパティを更新して通知する "set"関数を使って連絡先を変更することでこれを修正できます。これを行うには2通りの方法があります:
a。 @Property(通知:true)
@PolymerRegister('contact-tile')
class ContactTile extends PolymerElement {
factory ContactTile(Contact contact, Element parent) {
ContactTile tile = new Element.tag('contact-tile');
tile.contact = contact;
return tile;
}
ContactTile.created() : super.created();
@Property(notify: true)
Contact contact;
}
b。 polymerElement.set( "name"、value);
@PolymerRegister('contact-tile')
class ContactTile extends PolymerElement {
factory ContactTile(Contact contact, Element parent) {
ContactTile tile = new Element.tag('contact-tile');
// tile.contact = contact;
tile.set("contact", contact);
return tile;
}
ContactTile.created() : super.created();
@property
Contact contact;
}
はまた、オブジェクトの属性にアクセスするために、私は(メソッドまたは@reflectable)JsProxyを拡張し、すべての属性に@propertyを追加するためのクラスをしなければなりませんでした。 Contact
クラスがフルカスタム要素ではないので
import 'package:polymer/polymer.dart';
class Contact extends JsProxy {
@property
String contactId;
@property
String firstName;
@property
String surname;
Contact(Map map) {
contactId = map['contactId'];
firstName = map['firstName'];
surname = map['surname'];
}
}
私はすでにそれをテストしましたが、何らかの理由で動作していませんが、あなたの言うことを意味します。私は実際に何が起こっているのか分かりません。 –
ハードコードされた値の連絡先を使用してデバッグしようとしましたか?それがうまくいけば、 'insertTile'が準備完了した後で通知が欠落していると思います。 –
通知が鍵でした! ポリマー0.5ではプロパティを変更でき、自動的に通知が行われます。ポリマー1では、プロパティを変更して起動するように見えますが、関数 "set"を使用する必要があります。私は解決策で自分の質問を更新します。 ありがとうございました! –