-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dom-repeat data binding: not working as expected #1758
Comments
As per https://www.polymer-project.org/1.0/docs/migration.html#data-binding
Try: <template is="dom-repeat" items="{{items}}">
<p><span>{{item.code}}</span> - <span>{{item.name}}</span></p>
</template> |
Or something like...
|
Thanks both, I read and still missed it when trying in code, but still I tried both approaches, jshint is not complaining but still keep getting similar results: Code: Output: |
@vl4dt - Try changing your items: {
type: Array,
value: function() { return []; },
notify: true
} As per https://www.polymer-project.org/1.0/docs/devguide/properties.html#configure-values (_emphasis_ mine):
|
Maybe you need to use the new set or notify api.. https://www.polymer-project.org/1.0/docs/devguide/properties.html#observing-path-changes Try a notify on items |
@robrez is correct.
Alternately, if you're refreshing the entire list, you could do:
This takes advantage of the fact that changing a direct property like |
It would also be helpful if you share the markup that generates your output (the one that uses your element) |
Thanks all, finally works! @punzki I was lazy and just took the Polymer Starter Kit, modified the index.html that comes with the it, replaced the contact section content like this: <section data-route="contact">
<paper-material elevation="1">
<el-test></el-test>
</paper-material>
</section> The final solution was the sum of all fixes suggested, both approaches suggested by @arthurevans and @robrez worked just fine, the binding was wrong as @punzki pointed, to sum it all, here is the final and working code: <dom-module id="el-test">
<style>
:host {
display: block;
}
@media (max-width: 600px) {
h1.paper-font-display1 {
font-size: 14px;
}
}
</style>
<template>
<h1 class="paper-font-display1">
List of Items
<paper-icon-button
icon="refresh"
on-tap="refreshItems">
</paper-icon-button>
<paper-icon-button
icon="refresh"
on-tap="refreshItemsB">
</paper-icon-button>
</h1>
<p>This is the complete list of items</p>
<div>-- START --</div>
<template is="dom-repeat" items="{{items}}">
<p>
<span>{{item.code}}</span> - <span>{{item.name}}</span>
=
<span>{{_concat(item.code, item.name)}}</span>
</p>
</template>
<div>-- END --</div>
</template>
</dom-module>
<script>
(function() {
Polymer({
is: 'el-test',
properties: {
greeting: {
type: String,
value: 'Bienvenido',
notify: true
},
items: {
type: Array,
value: function() { return []; },
notify: true
}
},
refreshItems: function() {
var tmp = [];
for (var i = 0; i < 10; i++) {
tmp.push({
code: i + 1,
name: 'Item #' + (i + 1)
});
}
this.items = tmp;
},
refreshItemsB: function() {
for (var i = 0; i < 10; i++) {
this.push('items', {
code: i + 1,
name: 'Item #' + (i + 1)
});
}
},
_concat: function(v1, v2) {
return v1 + ' - ' + v2;
}
});
})();
</script> Thanks a lot! |
I am trying to assign value to attribute inside but its not working while values are displayed correctly in text context. example:
in above case data-route for anchor is not set but name is appearing. any help .. |
Try The docs talk about property vs attribute binding here: And binding to native elements here: The spec recommends using |
What am I missing?
http://jsbin.com/xukibu/1/
Output (excerpt):
http://jsbin.com/videze/2/
The text was updated successfully, but these errors were encountered: