polymer - push is not defined

215 views
Skip to first unread message

mon...@monkatron.com

unread,
Aug 1, 2015, 5:29:06 AM8/1/15
to Polymer
Hi 
Im experienced dev (15 years +) but new to Polymer. 

I am stuck while i try and update an array with objects loaded in from external api.

moltin.Authenticate( function() {

window.addEventListener( 'MoltinReady', function(response) {

moltin.Product.List({category:'11533901100405'}, function(product) {

for( obj in product ){
this.push('spices', obj)
}
});

});
}); 

Using polymer from bower and the issue reported in chrome is Uncaught TypeError: this.push is not a function - am i missing an import or something?

Eric Bidelman

unread,
Aug 1, 2015, 1:28:26 PM8/1/15
to mon...@monkatron.com, Polymer
`this` in that context isn't and instance of Polymer.Base, but moltin.Product. You'll need to bind the call your element object.

We typically don't recommend people use the array methods (push/splice/pop) outside of their Polymer element. Is there a reason you can't just do:

moltinElement.product =  product; 

in that callback and have your element handle adding objects to the spices array?


Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/25c383bc-9c20-4e89-948f-bb3ef0e800e1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages