Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8891883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:51:09+00:00 2026-06-14T22:51:09+00:00

I’ve got an issue where I’m using template.render to render an array of items

  • 0

I’ve got an issue where I’m using template.render to render an array of items based on a html template. Each item in the array also contains another array, that I want to bind to another template, within the parent element for the area. I know I can use a grid layout for groups, but I’m trying to accomplish this another way, so please, no suggestions to use a different control, I’m just curious as to why the following doesn’t work correctly.

   //html templates
   <div id="area-template" data-win-control="WinJS.Binding.Template">
    <h1 class="area-title" data-win-bind="innerHTML:title"></h1>
    <div class="items">

    </div>
  </div>

<div id="item-template" data-win-control="WinJS.Binding.Template">
    <h2 class="item-title" data-win-bind="innerHTML:title"></h2>
</div>

   // JS in ready event
   var renderer = document.getElementsByTagName('section')[0];
            var area_template = document.getElementById('area-template').winControl;
            var item_template = document.getElementById('item-template').winControl;
            for (var i = 0; i < areas.length; i++) {
                var area = areas.getAt(i);
                area_template.render(area, renderer).done(function (el) {
                    var item_renderer = el.querySelector('.items');
                    for (var j = 0; j < area.items.length; j++) {
                        var item = area.items[j];
                        item_template.render(item, item_renderer).done(function (item_el) {
                        });
                    }
                });
            }

So what should happen, is that after it renders the area, in the “done” function the newly created element (el) gets returned, I’m then finding it’s “.items” div to append the items to. However, this appends all the items to the first div created. If it was the last div, it might make more sense due to closures, but the fact it happens on the first one is really throwing me off!

What’s interesting, is that if I replace my template render function using document.createElement and el.appendChild, it does display correctly e.g: (in the done of area render)

 area_template.render(area, renderer).done(function (el) {
    var item = area.items[j];
    var h2 = document.createElement('h2');
    h2.innerText = item.title;
    el.appendChild(h2);
}

although I’ve realised this is el it is appending it to, not the actual .items div of the el

I’m not quite sure what could be going on here. It appears the value of el is getting updated correctly, but el.querySelector is either always returning the wrong “.items” div or it’s getting retained somewhere, however debugging does show that el is changing during the loop. Any insight would be greatly appreciated.

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:51:10+00:00Added an answer on June 14, 2026 at 10:51 pm

    I’ve worked out what is going on here. The “el” returned in the render promise is not the newly created element as I thought. It’s the renderer and the newly created html together. Therefore el.querySelector(‘.items’) is always bringing back the first ‘.items’ it finds. I must have misread the docs, but hopefully someone else will find this information useful in case they have the same error.

    I guess one way around this would be to do item_rendered = el.querySelectorAll(‘.items’)[i] and return the numbered ‘.items’ based on the position in the loop

    e.g

       for (var i = 0; i < areas.length; i++) {
                    var area = areas.getAt(i);
                    area_template.render(area, renderer).done(function (el) {
                        var item_renderer = el.querySelectorAll('.items')[i];
                        for (var j = 0; j < area.items.length; j++) {
                            var item = area.items[j];
                            var h2 = document.createElement('h2');
                            h2.innerText = item.title;
                            item_renderer.appendChild(h2);
                        }
                    });
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i got an object with contents of html markup in it, for example: string
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.