Template repetition in Polymer JS not rendering array properly in Chrome browser

I can't seem to get this code to work properly.

<template repeat="{{item in list}}"> </template>

Although, I have also attempted the following method which resulted in errors:

<template is="dom-repeat" id="example" items="{{list}}"></template>

The errors related to is="dom-repeat" are as follows:

Uncaught TypeError: Polymer.dom.addDebouncer is not a function
Uncaught TypeError: Polymer.dom is not a function

What could be causing this issue?

Below is my code snippet:

<link rel="import" href="../lib/iron-ajax/iron-ajax.html">

<link rel="import" href="../lib/polymer/polymer.html">

<link rel="import" href="welcome-title.html">

<dom-module id="remove-user">

<template>
  <iron-ajax id="getAll" url="http://localhost:3002/secure/api/all" method="GET" handle-as="json" on-response="getAllCB" with-credentials='true'></iron-ajax>

    <div class="ui relaxed stackable grid centered" id="admin-container">
        <welcome-title class="ui center aligned row grid"></welcome-title>
        <form class="ui grid remove-user hide twelve wide column" method='post' action="/secure/add-user">
            <h3>Remove User</h3>

            <table class="ui unstackable celled table ">
                <thead>
                    <tr><th class="nine wide">Username</th>
                        <th class="three wide">Permission</th>
                        <th class="one wide"></th>
                    </tr>
                </thead>
                <tbody> ...

Here's where I'm stuck. The content inside the repeat doesn't display on the page even though everything else outside of it does. There are no console errors present.

                    <template repeat="{{user in users}}">
                        <span>{{user}}</span>
                    </template>

Why is the content within the repeat not being rendered on the page?

                    ... <tr>
                        <td><span></span></td>
                        <td></td>
                        <td class="collapsing">
                            <div class="ui fitted checkbox">
                                <input type="checkbox"> <label></label>
                            </div>
                        </td>
                    </tr>

                </tbody>
                <tfoot class="full-width">

                    <tr><th colspan="3">

                        <button class="right floated negative ui button"><i class="remove user icon"></i>Remove User(s)</button>
                    </th>
                </tr></tfoot>
            </table>
        </form>
    </div>

</template>



</dom-module>
<script>

Polymer({

    is: "remove-user",

    ready: function(){

        this.$.getAll.generateRequest();

    },

    getAllCB: function(data){

        this.users = data.detail.response;
    }

});

</script>

When viewing the users JSON object through the browser console using JSON.stringify(), here is what it looks like:

[{"username":"admin","permission":"admin"},            
{"username":"admin","permission":"application1"},
{"username":"user","permission":"application1"},
{"username":"test","permission":"application1"}]

To access the entire project: The specific file mentioned can be found at

authentication/public/elements/remove-user.html
The main page that loads this element is located at authentication/secure.html For more information, visit https://github.com/CoultonF/Web-Development-3-Node.JS

Answer №1

It seems that you are trying to incorporate an expression into a data binding, which is not supported in Polymer 1.x (and isn't planned for 2.x).

The correct format of the code should be:

<template repeat="{{user in users}}">
  <span>{{user}}</span>
</template>

should be written like this:

<template is="dom-repeat" items="{{users}}" as="user">
  <span>{{user}}</span>
</template>

HTMLImports.whenReady(() => {
  Polymer({
    is: 'x-foo',
    properties: {
      users: {
        type: Array,
        value: () => ['Andy', 'Bob', 'Charlie']
      }
    }
  });
});
<head>
  <base href="https://polygit.org/polymer+1.7.1/components/">
  <script src="webcomponentsjs/webcomponents-lite.min.js"></script>
  <link rel="import" href="polymer/polymer.html">
</head>
<body>
  <x-foo></x-foo>

  <dom-module id="x-foo">
    <template>
      <template is="dom-repeat" items="{{users}}" as="user">
        <span>{{user}}</span>
      </template>
    </template>
  </dom-module>
</body>

codepen

To learn more about the dom-repeat template, check out the Polymer docs.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Runtime.UnhandledPromiseRejection - Oops! Looks like we're trying to read properties of something that doesn't exist (specifically 'headers')

I'm facing an unexpected error that has left me puzzled. Let me walk you through what I am trying to accomplish: The task at hand involves fetching data from one API and then transmitting it to another. This process is executed as a background-funct ...

Creating a Three by Three Grid with HTML and CSS

I have a total of 20 elements to display in a grid view. However, I specifically want a 3x3 grid view, where only 9 elements will be visible in the view window. The remaining elements should be placed on the right side of the window in a scrollable manner. ...

Error in three.js: Attempting to access the 'rotation' property of an undefined object

As I try to animate a cube in my scene, I keep encountering an error that reads: "TypeError: Cannot read property 'rotation' of undefined." function animate() { requestAnimationFrame( animate ); render(); } ...

Library for HTML styling in JavaScript

Is there a reliable JavaScript library that can automatically format an HTML code string? I have a string variable containing unformatted HTML and I'm looking for a simple solution to beautify it with just one function call. I checked npmjs.com but co ...

What is the best way to set up prettier in VSCODE so that it organizes jsx attributes across multiple lines?

My preference is for the following syntax: <input id="inputForEmail" type="email" className="form-control" aria-describedby="Enter email address" placeholder="Enter emai ...

How to dynamically load bootstrap-multiselect within a loop in a vueJs application

I am attempting to dynamically load bootstrap-multiselect in a loop using VueJs. My desired implementation looks something like this: <div class="col-xs-6 col-sm-4 mb-1" v-for="params in param"> <select class="mult" multiple="multiple"> ...

Incorporate a new class into the slot's scope

I'm developing a custom table feature that allows users to customize <td> elements using a slot. Here's the current setup: <tbody> <tr v-for="(item, key) in items"> <slot :item=item"> <td v-for="(header, he ...

Building a secure form validation system with Bootstrap 4 and integrating Stripe checkout functionality

Can someone help me figure out how to display the Stripe payment popup only when the Bootstrap 4 form is valid? ✔ The Bootstrap code is functioning correctly when the form is invalid. ...

Delaying the intensive rendering process in Vue.js and Vuetify: A comprehensive guide

Recently, while working on a project with Vue.js 2 and Vuetify 2.6, I encountered an issue with heavy form rendering within expansion panels. There seems to be a slight delay in opening the panel section upon clicking the header, which is most likely due t ...

Scala can read, write, and format data for non-case classes

When it comes to serializing a regular class in Scala, I'm familiar with how to serialize a case class using the simple implicit val caseClassFormat = Json.format[CaseClass] However, I'm unsure about how to go about serializing a regular class. ...

AngularJS dropdown with multiple selections within a Bootstrap modal

Being new to AngularJS, I apologize for asking this question in advance. I am utilizing Angular bootstrap modal from the following link: https://angular-ui.github.io/bootstrap/ and multiple select dropdown list from: https://codepen.io/long2know/pen/PqLR ...

Changing the style of characters within a contenteditable element

Seeking advice on how to implement an input element that changes style (like font color) between two specific characters (such as '[' and ']'). I'm considering using a contenteditable div but open to other suggestions. Currently ex ...

Encountering a crash with the NativeDroid HTML5 JS css jQueryMobile template on iOS7

Recently, I began working on a mobile solution using the NativeDroid template, an HTML5 JS CSS template available at . However, a friend informed me that the template does not work on iOS7 devices. I tested it on multiple devices. Even when running the de ...

Using jQuery to update text for corresponding element upon input change

I'm working on a user-friendly ICE card generator. Users can input their information in the form fields and see a live preview below. While the current code functions correctly, it requires repetitive copying and pasting for each input/element pair. ...

The paths required are not correct following the transpilation of a TypeScript file using Babel

Issue Every time I use nodemon with npm run start, I encounter the error message "Error: Cannot find module 'Test'". Similarly, when I build files using npm run build and try to run ./dist/index.js, I face the same issue. It seems that the requ ...

When a function is included in an object, it transforms into something other than a function

In my model, it looks like this: export default class UserObject { name: string; id: string; validateInsert() { } } If I interact with the model in this way: const modelUser: UserModel = new UserModel(); modelUser.ID = 1; modelUser ...

How do I execute a Next.js script that utilizes `fs` and `sharp` during development with Webpack?

I'm working on creating a basic GIFPlayer that displays a GIF when the play button is clicked, and shows a PNG otherwise: <img className="w-full h-full" src={isPlaying ? gifPath : imgPath} alt={pic.alt} /> Since I only have a GIF file ...

The two-word string is failing to pass through the query string

I've been working on passing multiple values through the query string. So far, I have successfully passed single-word values to a PHP page using jQuery. However, I encountered an issue when trying to pass a user's name like "Vishal Deb" as it onl ...

Delete multiple selected rows from the table

I need help with removing multiple rows from a table. I've tried the code below but it doesn't seem to work. I'm using DataTables v1.10.9. $('#del_Btn').on('click', function () { // 'table' is the instanc ...

A step-by-step guide on merging two JSON arrays in PostgreSQL

I am in need of merging two JSONB Arrays In my table column, I have a jsonb of items structured like this: [ {"fav": 1, "is_active": true, "date": "1999-00-00 11:07:05.710000"}, {"fav": 2, "is_active": true, "date": "1998-00-00 11:07:05.710000"} ] ...