Niklas Lang Niklas Lang - 1 year ago 85
JSON Question

Store returned values from the iron-ajax request in variables (Polymer)

I am working the first time with Polymers iron-ajax element and came across a problem which I believe is fairly simple to solve but I am unable to find a solution online.

I retrieve user details with the iron-ajax element and loop through it with the dom-repeat. The first and last name of a user are getting placed in a custom card element that I created to display users. Everything works fine except that I am unable to store the returned id value in a variable.
I am sure this is possible with the usage of data binding but I couldn't get it to work. And even when I try to get the value with getAttribute in my JavaScript it just returns null.

In the code below my iron-ajax request & response can be found including my awkward attempt to get the id value {{}}.To do so I created a on-tap function when a user clicks on one of the cards which then should get the value of the stdId attribute.

<dom-module id="my-students-view">

:host {
display: block;

<!-- Iron-Ajax created connection and gets data -->

<!-- dom-repeat iterates the response -->
<template is="dom-repeat" items="[[]]" sort="sortData">
name="{{item.first_name}} {{item.last_name}}"


is: 'my-students-view',

properties: {
stdId: {
notify: true,

//Sort the array/data alphabetically
sortData: function(a, b) {
if(a.first_name < b.first_name) return -1;
if(a.first_name > b.first_name) return 1;
return 0;

//Try to get the id value of a the student card
sendId: function() {
var idPropertie = this.$$("#studentCard");
var idValue = idPropertie.getAttribute('stdId');
console.log('the id is:' + idValue);



Answer Source

Rewrite the sendId function:

sendId: function(event) {
  var idValue =;
  console.log('the id is:' + idValue);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download