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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:15:29+00:00 2026-06-05T13:15:29+00:00

Currently playing about with KnockoutJS. Just trying to update an observable array from a

  • 0

Currently playing about with KnockoutJS. Just trying to update an observable array from a ajax/json feed (using twitter) in this example.

It seems to lose scope of what “this” is when trying to update my observable array (currentTweets). I’ve tried adding bind to various places but no such luck.

The error I get is: Uncaught TypeError: Cannot call method ‘push’ of undefined

I’m sure I am doing something stupid, here it is in action (not much to look at!)

http://jsbin.com/oyuteb

I’ve read a lot about Knockout mapping but don’t feel confident enough to take that on yet!

So, any help or guidance would be fab.

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-05T13:15:34+00:00Added an answer on June 5, 2026 at 1:15 pm

    The simplest way to solve this is to proxy your viewmodel’s “this” into another variable so it is available inside handlers. When jquery ajax calls the success handler, the context is different so this refers to something else.

    So you would have

    function twitterViewModel() {
        var self = this;
        this.currentTweets = ko.observableArray([]);
        ...
    
        this.getTweets = function(){
    
            $.ajax({
                dataType: 'jsonp',
                url: 'http://search.twitter.com/search.json?callback=?&q=' 
                         + this.searchTerm() + '&rpp=50',
                success: function (data) {
                    $.each(data.results, function(i,tweet){
                        self.currentTweets.push({'keywords' : 'bugger'});
                    });
                }
            });
        }
    }
    

    You can eliminate the bind calls and use self instead.

    Hope this helps.

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

Sidebar

Related Questions

I'm playing and trying to learn a little more about AJAX in MVC. Currently,
We are currently using SubSonic 3.0.0.2 and playing about with the Linq for it,
I am currently learning about basic networking in java. I have been playing around
I'm currently playing around with RestEasy and Angular.js. I'm trying to return a collection
I am currently playing with Qt trying to set up a small particle system.
I'm currently playing around with tipfy on Google's Appengine and just recently ran into
I am currently playing a video in andriod from the url http://daily3gp.com/vids/747.3gp its working
Sorry about the weird title, I'm currently playing around with WinForms and I'm wondering
I'm currently playing with ARM assembly on Linux as a learning exercise. I'm using
Currently I'm playing with faceted search after reading RavenDB doc about it. The result

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.