locked
Unable to get property 'push" of undefined or null reference when calling list.push (WINJS List function) RRS feed

  • Question

  •             var appsList = WinJS.Binding.List();
    
                WinJS.xhr({ url: "http://localhost:52241/Myservice.svc/getApps" }).then(function (xhr) {
                    var apps = JSON.parse(xhr.response);                
                    apps.forEach(function (i) {
                        appsList.push({
                            applicationId: i.ApplicationId,
                            applicationName: i.ApplicationName
                        });                    
                    });
    

    Error

    I am trying to bind a JSON object data to a WINJS list (for windows 8 app). I am getting the above error when calling the list with "push". Not sure whats going wrong here. Any tips to resolve this issue.

    Here is my JSON data for reference:

    [{"ApplicationId":1,"ApplicationName":"ABC","GroupId":1},{"ApplicationId":2,"ApplicationName":"DEF3","GroupId":2},{"ApplicationId":3,"ApplicationName":"ABC1","GroupId":2},{"ApplicationId":4,"ApplicationName":"DEF2","GroupId":2},{"ApplicationId":5,"ApplicationName":"FGH1","GroupId":3},{"ApplicationId":6,"ApplicationName":"FGH2","GroupId":3},{"ApplicationId":7,"ApplicationName":"IJK","GroupId":3},{"ApplicationId":8,"ApplicationName":"IJK1","GroupId":3}]

    Thursday, December 27, 2012 4:03 AM

Answers

  • Folks,

    I am able to resolve the issue after posting this thread :) Zeeeees....I spent lot of time to crack this simple mistake....I forgot to add "new" keyword for var appsList = WinJS.Binding.List();

    Resolution : var appsList = new WinJS.Binding.List();


    • Marked as answer by SurfaceRocks Thursday, December 27, 2012 4:10 AM
    Thursday, December 27, 2012 4:10 AM