Updating Polymer template from parse.com callback.

64 views
Skip to first unread message

Hans Dulimarta

unread,
Aug 5, 2015, 1:44:07 AM8/5/15
to Polymer
I'm having issue updating a polymer 1.0 template from a Parse.com callback. This is my template:
<template is="dom-repeat" items="{{users}">
 
<div><span>{{item.name}}</span><div>
</template>


and this is my Parse.com query and callback:
Polymer({
 
is: "my-element",
  users
: [{name : "It's me"}],
  ready
: function() {
   
var userObj = Parse.Object.extends("Users");
   
var userQuery = new Parse.Query (userObj);
    userQuery.find().done(this.userLoaded.bind(this));
 
},

  userLoaded
:function(results) {
   
for (var i = 0; i < results.length; i++) {
     
var userData = results[i];
     
this.users.push({name: userData.get("name")});
    }
 
}
)

I verified with the debugger that inside userLoaded each element of the results array was correctly pushed to this.users. However, the template shows only one item ("It's me"), the other items returned by the Parse.query did not show up on the template.

I'm guessing that I misunderstood the function scoping details of either parse.com callback and polymer functions.

Eric Bidelman

unread,
Aug 5, 2015, 2:39:57 AM8/5/15
to Hans Dulimarta, Polymer

You need to use Polymer's array helper methods so  the template bindings see the changes.

https://www.polymer-project.org/1.0/docs/devguide/properties.html#array-mutation


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/c2b76cd2-03f5-4a61-b32d-452d22e0f454%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hans Dulimarta

unread,
Aug 5, 2015, 11:19:07 AM8/5/15
to Polymer, hans.du...@gmail.com
Thank you Eric. It works perfectly.
Reply all
Reply to author
Forward
0 new messages