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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:54:04+00:00 2026-06-09T23:54:04+00:00

I want to call collection’s method from the AppView. But It can’t. My code

  • 0

I want to call collection’s method from the AppView. But It can’t. My code is like this.

todolist.js

define(["todolist","todo"],function(TodoList,Todo){
    var TodoList = Backbone.Collection.extend({
            url: "/todos",
            initialize:function(){
                this.fetch();
                this.bind("add",this.update,this);
            },
            add:function(){
                console.log("added");
            },
            update:function(){
                    console.log("update!");

                    }
    });

    return TodoList;
});                                                                                                

app.js

 define(["jquery","underscore","backbone","todo","todolist","todo_view"],
    function($,_,Backbone,Todo,TodoList,TodoView){
        var AppView = Backbone.View.extend({
                initialize:function(){
                    this.collection = new TodoList;
                    this.collection.update();
                },
                events:{
                    "keypress #new-todo":"create",
                },
                    create:function(e){
                        if (e.keyCode === 13){
                            var txt = $("#new-todo").val();
                            var todo = new Todo({title: txt});
                            this.collection.add(todo.toJSON());
                        }
                    }
                }
        );
        return new AppView({el: $("body")});
});

      


    
    

                     

But I don’t know why this.collection.update() method outputs undefined. Do you have any idea?
And my all code is here https://github.com/haradashinya/my-todo-redis

Thanks in advance.

  • 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-09T23:54:06+00:00Added an answer on June 9, 2026 at 11:54 pm

    The mistake is in your app.js definition. It should return AppView not an instance of it, the instance should be created outside the module definition. As it is now, by the time it returns todolist is not yet defined.

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

Sidebar

Related Questions

I want to call a method say success(message) of javascript from android activity. I
I want to use a generic collection like Dictionary , but Dictionary requires that
For example, there is a collection like this: {market: 'SH', code: '000001', date: '2012-01-01',
I want to call a method of my class inside a lambda expression: void
I want to know what action is performed when we call Dispose() method. Is
I have a list of pairs (CarType(Enum), code(string)). Unfortunately in this collection codes are
This is an easy one, I am sure, but I can't seem to find
I have a STE and I want to clear navigation property collection like customer.Orders.Clear().
If I want to iterate through a collection, and call a function on each
I want to do the equivalent of e.g. this API explorer call using the

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.