Error encountered with underscore template - Unforeseen SyntaxError: Unexpected token <

I encountered an error when attempting to load one of my underscore templates. It seems to be related to an issue in the for loop, which I suspect should be a .each loop, but I'm still trying to grasp its structure.

Here is a snippet of my template:

    
    <script type="text/html" id="Customer-List-View">
    <p> Please click on a customer to select </p>
        <table >
            <thead>
                <th> Customer Name </th><th>Last Invoice date</th><th>Last item added</th>
            </thead>

            <tbody>
                <% for (var i = 0, i < customers.length, i++){ %>
                    <tr class="cusTableRow"  id="<%=customers[i].objectId %>" >
                        <td> <%= customers[i].custName %> </td>
                        <td> <%= customers[i].custLastInvoiceDate %> </td>
                        <td> <%= customers[i].CustLastItemDate %> </td>
                    </tr>

                <% }; %>
            </tbody>
        </table>
        <button id="customerAdd"> Add a new customer </button>

    <p> Here should be a set of buttons for working with customers </p>

</script>

The template is being invoked by the following code:

$('#tableDiv').html(_.template($("#Customer-List-View").html(), {'customers': globalCustomerList}));

I believe it's a simple issue, especially since it's my first time working with tables in templates. Any assistance would be greatly appreciated.

Thank you in advance!

Answer №1

The code snippet provided has a mistake in the use of commas instead of semicolons within the for loop.

<% for (var i = 0, i < customers.length, i++){ %>

A correction should be made to:

<% for (var i = 0; i < customers.length; i++){ %>

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

Tips for creating a mock for a function that yields a JSX Element

I am facing a problem where I have a function that returns a JSX Element. Here is a snippet of the code: myFunction.jsx const myFunction = (props) => { // ... do something with props return <MyElement {...newProps} /> } // MyElement.j ...

"Retrieving the most recent data within an ng-repeat directive using AngularJS

I am facing an issue with ng-repeat in my application. It successfully fetches values from the database and displays them in input text fields. However, when I update these values and click the save button, the updated values are not being saved. Can someo ...

The socket.io.js file could not be located while using (nodejs with express [4.13] and socket.io [1.3])

Currently, I am utilizing express 4.13 and socket.io 1.3.2 along with an express generator. Here is the code snippet from my app.js: var app = express(); var server=require('http').createServer(app).listen(app.get('port'),'127.0. ...

The function getAttribute for isPermaLink is returning a null value when accessing an element within an RSS feed using

Struggling to retrieve the value of the isPermaLink attribute using protractor, I have attempted various methods. While successful in fetching values from other elements, the isPermaLink always returns null. HTML <guid isPermaLink="false">public-a ...

The event was triggered, however, some sections of the code did not run

I am currently working on a project called lan-info on GitHub. Here is the code snippet that I am using: let arpSweepCommand = './arpSweep.sh'; app.get('/arp', (req, res) => { console.log('we have a working signal!'); ...

Activating Bootstrap modal when a navigation link is clicked

Just started a site for a client and new to Bootstrap. I've got the layout down - full-width page with "Top Nav" within the nav bar, looking to create a modal effect drop-down. When clicking on "About", it should trigger the .modal function. However, ...

Iterate through a JavaScript grid and display the items

I am attempting to iterate through a JavaScript table, aiming to display the elements located between two selections made by the user. Here is an example of the table structure: if the user selects IDs 2 and 5, the loop should display rows 3 and 4. I trie ...

Having trouble getting Vue.js to cooperate with a brand new Laravel 5.8 setup?

I set up a fresh Laravel project using laravel new sample. Then I executed npm install followed by npm run dev. Next, I modified the welcome.blade.php file as shown below: <!DOCTYPE html> <html> <head> <script type="text/j ...

Guidance on creating a custom color selection tool for a specific task

Looking for assistance in converting a code snippet that uses <button> elements to select colors into a color picker. I am unsure how to retrieve the selected color and use it within a JavaScript function. Can someone provide guidance on this? Here i ...

What is the best way to retrieve the total number of options within a dynamically generated <select> element using JavaScript in JSP?

To generate a page, I use the following code: <%List<String> someList = new ArrayList<String>(); someList = SQL();%> <select id=Select> <% for (int i =0; i < someList.size(); i++) { %> <option value=<%= someLis ...

Change the div attribute when clicking on a corresponding link

For the full code, please visit: https://plnkr.co/edit/6TTLVcsXLV7C1qXSMQV0?p=preview Here is an angular ui bootstrap accordion with nested panels: <uib-accordion close-others="oneAtATime"> <div ng-repeat="sub in subdivisions"> < ...

Stop the setTimeout function after redirecting in the controller

I am experiencing an issue with my AJAX call as it keeps triggering my controller repeatedly. AJAX function <script type="text/javascript> var stopTime =0; var scoreCheck = function () { $.ajax({ url: "<?php echo 'http:// ...

Incorporate this form created externally onto my website

I have been working on my website and I am looking to incorporate a form that opens up once the login button is clicked. This form was generated using an online form builder which provides an embed code for seamless integration onto websites. Below, you wi ...

The process of eliminating body padding in Nuxt.js

I'm considering building a website using Nuxt.js because I've heard it's both cool and user-friendly. While I do have some knowledge of vue.js, I'm stuck on a particular issue: How can I remove the padding from the body? I understand ...

The Bootstrap 3.3 Carousel is stationary and does not rotate

I am facing a challenge with implementing a Carousel using Bootstrap version 3.3.7 on my website. The code snippet is as follows: <!-- Carousel ================================================== --> <div class="row dark-start d-none d-lg-block"&g ...

Parse a string in the format of "1-10" to extract the numbers and generate an array containing the sequence of numbers within the range

Looking to convert a string in the format "1-10" into an array containing the numbers within that range. Display the array on the screen using a for loop. For example, if "1-5" is provided, the resulting array should be: {1, 2, 3, 4, 5} Create a workflow ...

Tips for preserving data while attempting to access the schema

Attempting to store data from a book that includes author and genre information, referenced in separate files. The issue arises when making the reference in the main schema. Although the book carries details of the book itself, it fails to establish refer ...

Unable to display content when the button is triggered

I am facing an issue with hiding a div (class="login-form") and displaying it only after clicking the Login button on my HTML page using jQuery. However, despite clicking the button, the login form does not appear. Can anyone help me understand why this ha ...

What is the best way to stop event bubbling in react-router-dom when using the <Link> component?

Hey there! I have a situation that I need help with. I tried putting the Link around the whole post so that I could prevent bubbling for individual buttons, but for some reason stopPropagation() is not working as intended. Following advice from another s ...

Storing HTML values in a Meteor database is a common practice for web

Within my meteor project, I have a paragraph in HTML containing a JSON value as follows: {"Active Template Id":"6467","Shirt Brand":"levis","ProductId":"EB301","Brand":"on","Material":"cotton","Price":"1800","Combo Id":"S90"} I am looking to store this v ...