Skip to content

Instantly share code, notes, and snippets.

@Alos
Last active February 25, 2016 15:27
Show Gist options
  • Save Alos/ea00c53a9fa841009f68 to your computer and use it in GitHub Desktop.
Save Alos/ea00c53a9fa841009f68 to your computer and use it in GitHub Desktop.
Polymer Behaviour Question
<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/iron-selector/iron-selectable.html">
<dom-module id="my-element">
<template>
<style>
:host {
display: block;
}
</style>
<div>Hello from <span>{{items}}</span></div>
</template>
<script>
(function() {
'use strict';
Polymer({
is: 'my-element',
properties: {
//nothing to see here
},
//by adding this behavior here it means that this element has the 'items' attribute among other things
behaviors: [Polymer.IronSelectableBehavior],
ready:function(){
console.log(this.items);//my items should be here but no... nothing :(
}
});
})();
</script>
</dom-module>
//somewhere else where I can inspect myarray and confirm that is has "things" in it
<my-element items="[[myarray]]" selected="0"></my-element>
@Alos
Copy link
Author

Alos commented Feb 22, 2016

On somewhere-else element:
$0.myarray
[Object, Object]

On my-element:
$0.items
[]

@robdodson
Copy link

Hm it's interesting that you see an array at all and not just an undefined if it truly is undefined...

@Alos
Copy link
Author

Alos commented Feb 22, 2016

Indeed! I sort of assumed the behavior would initialize the items array tho.

@robdodson
Copy link

If it's bound to myArray I would think that it would since a binding is just shorthand for saying myElement.items = myArray. Are you able to put together a jsbin to illustrate this? Maybe it's a timing issue

@robdodson
Copy link

You can use bit.ly/polybin as a starter

@Alos
Copy link
Author

Alos commented Feb 25, 2016

Sorry, it took so long..work got in the way! Please have a look:
https://jsbin.com/kazide/edit?html,console,output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment