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 8824087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:31:13+00:00 2026-06-14T06:31:13+00:00

First, please excuse my naive question. I know there a simple answer, but I

  • 0

First, please excuse my naive question. I know there a simple answer, but I am currently learning JavaScript and BackBone simultaneously, and am running into a few problems.

I am simply trying to add a table to my view from a collection of info from my javascript file. Here is my js file:

(function(window,app,$){

    app.views.itemsIndex = Backbone.View.extend({
        id:"items-index",

        initialize:function(){

        },

        events:{

        },

        render:function(){
            template = new EJS({
                url:"js/templates/patron/items/itemsIndex.ejs"
            });

            this.$el.html(template.render());

            this.createDummies()

            return this;
        },

        createDummies:function(){

            var bookCollection = new app.collections.books();

            for (var i = 0; i < 10; i++) {
                var book = new app.models.book({title : 'title ' + i});
                bookCollection.add(book);

                var item = new app.views.itemsItem();
                this.$el.append(item.render().el);
            };

            console.log(bookCollection);
        }
    });

})(window,window.circulationApp || {},$)

I get an error when I try to render the view with the error Uncaught ReferenceError: book is not defined

below is my ejs file:

<td>
    <div class="td-wrap">
        <%= book.escape('title') %></td>
    </div><!-- .td-wrap -->

Any thoughts?

  • 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-14T06:31:14+00:00Added an answer on June 14, 2026 at 6:31 am

    Don’t understand the whole thing, but from my understanding you want to render a Collection of Books via <td> elements

    Looks EJS supports loops, so why not insert the Collection directly into the view, and loop over books ?

    <% for (var i = 0; i < books.length; i++) {%>
        <%= books[i].escape('title'); %>
    <% } %>
    

    createDummies would return the Collection :

    createDummies: function() {
        var bookCollection = new app.collections.books();
        for (var i = 0; i < 10; i++) {
            var book = new app.models.book({title : 'title ' + i});
            bookCollection.add(book);
        };
        return bookCollection;
    }
    

    To render it :

    var tpl = new EJS({
        url:"js/templates/patron/items/itemsIndex.ejs"
    });
    
    var booksCollection = this.createDummies();
    
    this.$el.html(tpl.render({books: booksCollection}));
    

    Ideally in Backbone only the render method should be used to fill your $el with HTML.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first post on stackoverflow, so please excuse me if my question
This is my first question, so please excuse me for any mistake I make.
First question on StackOverflow, so please excuse me if I haven't done all the
First off, I'm new to MVC, so please excuse the question if it's basic.
First of all please excuse me if the question it's in itself stupid. I've
First question here. Please excuse noob errors. I want to be able to refer
My first ever question here. Please excuse me, I have just entered into C++
Please excuse my lack of knowledge here but could someone let me know how
Please excuse the very novice question but I am about to embark on my
First, please excuse my ignorance in this field, I'm a programmer by trade but

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.