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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:13:53+00:00 2026-06-08T21:13:53+00:00

I have to code: window.TicketCollection = Backbone.Collection.extend({ model:Tickets, url:/index.php/tickets/viewJSON }); window.TicketsView = Backbone.View.extend({ tagName:’div’,

  • 0

I have to code:

window.TicketCollection = Backbone.Collection.extend({
    model:Tickets,
    url:"/index.php/tickets/viewJSON"
});
window.TicketsView = Backbone.View.extend({
    tagName:'div',
    initialize: function () {
        this.model.bind("reset", this.render, this);

    },
    render:function(eventName){
        _.each(this.model.models, function(ticket){
            $(this.el).append(new TicketListItemView({model:ticket}).render().el);
        },this);
        return this;
    }
});
window.TicketListView = Backbone.View.extend({
    tagName: "li",
    template:_.template($('#tickets-list-item').html()),
    render:function (eventName){
        $(this.el).html(this.template(this.model.toJSON));
        return this;
    }
});


var AppRouter = Backbone.Router.extend({
    routes:{
        "":"list"
    },
    list:function(){
        window.alert("alright");
        this.ticketList = new TicketCollection();
        this.ticketLists = this.ticketList.get();

        this.ticketListView = new TicketListView({model:this.ticketList});
        $("#ticketListHolder").html(this.ticketListView.render().el);
    },
});
var app = new AppRouter();
Backbone.history.start();
});

My php is as follows:

<?php header('Content-type: application/json');
echo json_encode(array("ticketID"=>"test", "ticketName"=>"1"));?>

The response from the php is:

[{"ticketID":"1","ticketName":"Fix the admin system"}]

HTML:

<div id="ticketListHolder">
    #


</div>
<script type="text/template" id="tickets-list-item">
        <div class="supTicket ticketHolder nobg">
        <div class="issueType">
        <span class="issueInfo"><%= ticketName %></span>
        <span class="issueNum">[ #<%= ticketID %>] - <%= fullName %></span>
        </div>
        </div>
</script>

I get the error: Uncaught ReferenceError: ticketName is not defined, it appears that it’s not parsing the json, instead reading it as one string block. Why is this error occuring, when my JSON is returning the correct data.

  • 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-08T21:13:55+00:00Added an answer on June 8, 2026 at 9:13 pm

    You don’t use collection.fetch anywhere. Your router probably should look like this

    var AppRouter = Backbone.Router.extend({
        routes:{
            "":"list"
        },
        list:function(){
            window.alert("alright");
            this.ticketList = new TicketCollection();
    
            this.ticketListView = new TicketListView({
                    model:this.ticketList,
                    el:$("#ticketListHolder") // I directly assigned #ticketListHolder as the el
            });
    
            this.ticketList.fetch();
        },
    });
    

    And a Fiddle with a mostly working version of your code http://jsfiddle.net/Cc9Ad/2/
    Some points you should check:

    • your ListView and your ItemView were the other way round,
    • as Daniel Aranda said in his answer, try to use collections and models for their intended purpose,
    • this.model.toJSON should have been this.model.toJSON()
    • set defaults on your models, fullName is not defined and would break the templating engine if used in this state

    The revised code

    window.Tickets=Backbone.Model.extend({
        defaults: {
            fullName :"No full name"
        }
    });
    window.TicketCollection = Backbone.Collection.extend({
        model:Tickets,
        url:"/index.php/tickets/viewJSON"
    });
    
    
    window.TicketsView = Backbone.View.extend({
        tagName:'li',
        template:_.template($('#tickets-list-item').html()),
    
        initialize: function () {
        },
        render:function(eventName){
            console.log
            $(this.el).html(this.template(this.model.toJSON()));
            return this;
        }
    });
    window.TicketListView = Backbone.View.extend({   
        initialize: function () {
            this.collection.bind("reset", this.render, this);
    
        },
    
        render:function (){
            this.collection.each( function(ticket){
                $(this.el).append(new TicketsView({model:ticket}).render().el);
            },this);
    
            return this;
        }
    });
    
    
            var ticketList = new TicketCollection();
    
            var ticketListView = new TicketListView({
                    collection:ticketList,
                    el:$("#ticketListHolder")
            });
    
    // ticketList.fetch();
    ticketList.reset([
        {"ticketID":"1","ticketName":"Fix the admin system"},
        {"ticketID":"2","ticketName":"The ticket 2"}
    ]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I notice when I have code like: http://jsfiddle.net/MtULf/1/ window.Todo = Backbone.Model.extend({ defaults: { title:
i want to run my view based window application with ticker.i have code for
I have code: function _filter() { var url = window.location; alert(url); alert(url.split(/)[1]); } When
Simple question, I have a window that was opened with this code window.open(URL, windowName,
I have the follow code: window.onbeforeunload = function() { $.post( 'script/ratings.php', { data: dataToServer,
I have some html5 postMessage code: window.addEventListener(message, FA.recieveMessage, false); That listener invokes this function:
I have this code: public class Window extends JFrame { public Window(){ ... JButton
The JavaScript code window.print() can print the current HTML page. If I have a
I have this code inside a iframe: window.addEventListener('message', function(e){ if(e.data == 'test') console.log(e); },
I have this code which draws a Window and NSView, and have set up

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.