Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen dynamically adding dart polymer elements, how do I get observable variables to on DOM
    primarykey
    data
    text
    <p>I am trying to change the default web application that uses the polymer library so that the polymer element is created and added to the DOM from DART code rather than including in the HTML. I have succeeded in adding the element to the DOM, but my observable variable are not being updated on the DOM. The events are being fired, and the values are changing. I have got the DOM to update using Observable.dirtyCheck(), however, this is apparently expensive, so am trying to figure out how to get polymer to update dom without dirtyCheck().</p> <p>So, In short, how to I get rid of Observable.dirtyCheck()???</p> <p><strong>dynamiccreate.dart</strong></p> <pre class="lang-dart prettyprint-override"><code>library dynamiccreate; import 'dart:html'; import 'package:polymer/polymer.dart'; main() { initPolymer(); //create click-counter element at runtime from DART, not HTML var NewElement = new Element.tag('click-counter'); NewElement.setAttribute("count", "5"); //Add to DOM querySelector('#sample_container_id').children.add(NewElement); } </code></pre> <p><strong>dynamiccreate.html</strong></p> <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;title&gt;Sample app&lt;/title&gt; &lt;link rel="stylesheet" href="dynamiccreate.css"&gt; &lt;!-- import the click-counter --&gt; &lt;link rel="import" href="clickcounter.html"&gt; &lt;!-- &lt;script type="application/dart"&gt;export 'package:polymer/init.dart';&lt;/script&gt; --&gt; &lt;script src="packages/browser/dart.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;DynamicCreate&lt;/h1&gt; &lt;p&gt;Hello world from Dart!&lt;/p&gt; &lt;div id="sample_container_id"&gt; &lt;!-- &lt;click-counter count="5"&gt;&lt;/click-counter&gt; --&gt; &lt;/div&gt; &lt;script src="dynamiccreate.dart" type="application/dart"&gt;&lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>clickcounter.dart</strong></p> <pre class="lang-dart prettyprint-override"><code>import 'package:polymer/polymer.dart'; /** * A Polymer click counter element. */ @CustomTag('click-counter') class ClickCounter extends PolymerElement { @published int count = 0; ClickCounter.created() : super.created() { } //increment gets called when dynamically adding object at runtime //But does not update count on DOM void increment() { count++; //Have to add this to update count in DOM Observable.dirtyCheck(); //&lt;&lt;&lt;---How do I get rid of this??? } } </code></pre> <p><strong>clickcounter.html</strong></p> <pre class="lang-html prettyprint-override"><code>&lt;polymer-element name="click-counter" attributes="count"&gt; &lt;template&gt; &lt;style&gt; div { font-size: 24pt; text-align: center; margin-top: 140px; } button { font-size: 24pt; margin-bottom: 20px; } &lt;/style&gt; &lt;div&gt; &lt;button on-click="{{increment}}"&gt;Click me&lt;/button&gt;&lt;br&gt; &lt;span&gt;(click count: {{count}})&lt;/span&gt; &lt;/div&gt; &lt;/template&gt; &lt;script type="application/dart" src="clickcounter.dart"&gt;&lt;/script&gt; &lt;/polymer-element&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload