1

What is the pattern to bind an array of data to an element, and have that element "auto update" when any part of the array changes?

Say in a script I bound an array to app.game.gameData = [] and then bound that array to an element

<template is="dom-bind" id="app">
...
  <game-mat screens={{game.gameData}}></game-mat>

I have my game-mat element set up with dom-repeat, it passes values to sub-elements, etc.

But I want game-mat to update when I add a new item to game.gameData. Show the new row, etc. And, I want the sub-elements to change because of the binding set up, like if I change game.gameData[3].value = 50, I want that to be reflected in that sub element.

From what I can tell now, the only array that renders is the initial one created.

I want to manipulate this data and have it be reflected in that list of elements. Any good way to do that?

(I'd gladly change my existing patterns around, just don't know of a way to go about this right now...)

2
  • how do you insert values to the array? you need to do this with this.set() / this.push() polymer-project.org/1.0/docs/devguide/templates.html Commented Jan 8, 2016 at 3:50
  • Yes, I overlooked that! Good catch, that appears to be it. I access the Polymer element using a query selector in the "external" (i.e. non-Polymer) script can can use those .push() methods there. Thanks! Type up an answer and I'd accept it, if you feel like it) Commented Jan 8, 2016 at 12:13

1 Answer 1

1

Update Your array with push, pop, splice, shift, unshift methods.

for example push object to this.employees:

 this.push('employees', { first: 'Jack', last: 'Aubrey' });

or set sub-element

 this.set('employees.0.manager.type', 'engineer');

for more information you can read the polymer guide for arrays in https://www.polymer-project.org/1.0/docs/devguide/templates.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.