var Feed = function (searchTerm, feeditems)
{
this.ID = 1;
this.SearchTerm = searchTerm;
this.FeedItems = ko.observable(feeditems);
};
var FeedItem = function(userName, message)
{
this.UserName = userName;
this.Message = message;
};
var viewModel = {
Feeds: ko.observableArray(),
ShowRenderTimes: ko.observable(false)
};
ko.applyBindings(viewModel);
I am getting initial set of Feeds (just 1 Feed for now) from server no problem:
function getLatestFeeds()
{
$.getJSON('/Feed/GetLatestFeeds', function (data)
{
$.each(data, function ()
{
viewModel.Feeds.push(new Feed(this.SearchTerm, this.FeedItems));
});
});
}
then I am trying to update the FeedItems for that single Feed:
function getFeedData()
{
var url = "/Feed/GetFeedData";
$.getJSON(url, function (data)
{
$.each(data, function ()
{
//HERE IS THE PROBLEM: viewModel.Feeds(0).FeedItems.push(new FeedItem(data.UserName, data.Message));
});
});
}
I am getting an error:
'unable to get 'push'. object is undefined..' So what is the exact syntax to update the FeedItems of the Feed?
I understand that the question is more javascript related than knockout, but as I am getting it while trying to make ko work, I placed my question in this forum. Thanks for any help!
Al