javascript - "Foreach" loop throw an error -
It looks simple, but I do not understand. So I have HTML
div class = "ui three column grid" data-bound = "foreach: stories" & gt; & Lt; Div class = "column" & gt; & Lt; Div class = "ui stacked segment" & gt; & Lt; Div class = "ui three column grid center align" & gt; & Lt; Div class = "column" & gt; & Lt; Div class = "ui button icon" & gt; & Lt; Div class = "UI button short" & gt; & Lt; I class = "icon plus" & gt; & Lt; / I & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div class = "column" & gt; & Lt; Div class = "ui label circular" & gt; & Lt; Div class = "ui label" & gt; 124124 & lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div class = "column" & gt; & Lt; Div class = "ui button icon" & gt; & Lt; Div class = "UI button short" & gt; & Lt; I class = "sign zero" & gt; & Lt; / I & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div class = "ui grid center align" & gt; & Lt; Div class = "row" & gt; & Lt; Div class = "column" & gt; & Lt; H1 & gt; Yo & lt; / H1> & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div class = "row" & gt; & Lt; Div class = "column" & gt; & Lt; Div class = "ui section" data-bind = "foreach: {data: stories.strings, like: 'string'}" & gt; & Lt; P data-bound = "text: string" & gt; & Lt; / P & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; Define my JS file with
(['knockout', 'datacontact'], function (to, datacontext) {viewModel = Activate: Main: Ko.SourceWeb (Stories), stories: K. OswevableAurre ([]),} Return ViewModel; Activate Function () {Return DataContacts.Gate Stories (.) Then (Function (data) {Console.log (Data.results); _.each (data. Result, function (result) {console.log (results.strings); Themodel.story.pash ({strings: results .string});}); console.log (viewModel .stories ());});}}) then foreach: Stories' is not working, that's the problem. The console shows me that "unable to binding process" foreach: function () {return stories} "message: unable to binding process": foreach: function () {return: {stories: stringings such as: 'string'} } "Message: stories are not defined;"
Exception is being thrown out due to its second foreach Is: & lt; Div class = "ui segment" data-bind = "foreach: {data: stories.strings, as: 'string'}" & gt; & Lt; P data-bound = "text: string" & gt; & Lt; / P & gt; & Lt; / Div & gt; Because you are in the context of writing "stories", throws stories.strings because there is no stories property Stories items so that you just have to type the string
Comments
Post a Comment