Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot call method 'push' of undefined
    primarykey
    data
    text
    <p>I had this working in a fiddle just fine (which I can't find now), but when I moved it to VS2012 I'm getting the error "Cannot call method 'push' of undefined'. </p> <p>In the code below, the createItemDiv() function works great and creates the UI elements. It's the line before that, showItem() which calls this.visibleItem.push() that is throwing the error. I had a problem with this in the fiddle originally and added the "this" to fix it. If I remove "this" as it is now, I get "visibleItem is not defined".</p> <p><strong>viewmodel.js</strong></p> <pre><code>var dummyResults = [ { //sample data is here } ] var dummyItems = [ ] function VisibleItem(data) { var self = this; this.name = ko.observable(data.name); this.type = ko.observable(data.type); this.description = ko.observable(""); } function SearchResult(data) { var self = this; this.name = ko.observable(data.name); this.type = ko.observable(data.type); } var viewModel = { searchResult: ko.observableArray(ko.utils.arrayMap(dummyResults, function (item) { return new SearchResult(item); })), visibleItem: ko.observableArray(ko.utils.arrayMap(dummyItems, function (item) { return new VisibleItem(item); })), showItem: function (item) { this.visibleItem.push(item); } }; ko.applyBindings(viewModel); </code></pre> <p><strong>site.js</strong></p> <pre><code>$(document).on('click', '.result', function () { var item = ko.dataFor(this); viewModel.showItem(item); //add item to "visibleItems" viewmodel for management createItemDiv(item); //ui function to show item on screen }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload