Knockout.js foreach not showing list of items


Ronald McDonald

this doesn't work

                <div data-bind="foreach:nonAdminIB">
                    <div><span data-bind="text: explanation"></span>&nbsp;</div>
                </div>

This does show the data, but I've hardcoded the index number and I don't really know how many items there will be.

                <div><span data-bind="text: nonAdminIB[0].explanation"></span>&nbsp;</div>
                <div><span data-bind="text: nonAdminIB[1].explanation"></span>&nbsp;</div>

This is the data sent to the browser

  "nonAdminIB": {
    "0": {
      "nonAdminIrregularBehaviorId": 383,
      "irregularBehaviorId": 5,
      "irregularBehaviorDescription": "Falsified Information",
      "explanation": "Falsification of information on applications/scheduling permits."
    },
    "1": {
      "nonAdminIrregularBehaviorId": 384,
      "irregularBehaviorId": 6,
      "irregularBehaviorDescription": "Falsified Score",
      "explanation": "Falsification of score information. "
    }

How do I get the foreach service?

smaller

nonAdminIBCurrently an object, foreachonly works with arrays.

You have to convert it to an array:

var nonAdminIBArray = [];

for(var prop in nonAdminIB) {
  if(nonAdminIB.hasOwnProperty(prop)) {
    nonAdminIBArray.push(nonAdminIB[prop]);
  }
}

Then use nonAdminIBArraywith knockout .

Related


Reorder items in a list using knockout JS

Paul I have an array of observable items. One of the properties of "item" is "position", which represents the position of the item in the list. I want to be able to reorder the items on the page by placing a position with a dropdown menu next to each item. Whe

How to add and remove items from a list using Knockout JS?

steven I'm trying to learn Knockout and I'm following these two tutorials: Tutorial 1 Better List Examples But after half a day of trying (failed), I can't add or remove items. Here is my fiddle . Any help would be greatly appreciated! Clarify why self.items.p

How to add and remove items from a list using Knockout JS?

steven I'm trying to learn Knockout and am following these two tutorials: Tutorial 1 Better List Examples But after half a day of trying (failed), I can't add or remove items. Here is my fiddle . Any help would be greatly appreciated! Clarify why self.items.pu

Items in list list are not showing

username It shows idfichier, nomclient shows system.linq.enumerable...I guess it is showing the type of nomclient. public static void generateCTAF(string pathXml, string outputPDF) { List<FichierCTAF> fc = new List<FichierCTAF>();

Items in list list are not showing

username It shows idfichier, nomclient shows system.linq.enumerable...I guess it's showing the type of nomclient. public static void generateCTAF(string pathXml, string outputPDF) { List<FichierCTAF> fc = new List<FichierCTAF>();

Knockout observableArray - added items not showing in view

Garip Trying to add an item to observableArray in culling. While the item is indeed added to the view model, it is not added to the view. Seems to be related to using ko.mapping.fromJS. Reproduces the problem I'm facing here: function ViewModel() { var vm

Knockout Js template not showing data

username I have the following knockout js code, for some reason booking.text is not showing, see no text in column 1. Can anyone suggest what I am doing wrong and how to fix it? You can see the code in action in JS Fiddle here. http://jsfiddle.net/w3fxtdq8/18/

Knockout Js template not showing data

username I have the following knockout js code, for some reason booking.text is not showing, see no text in column 1. Can anyone suggest what I am doing wrong and how to fix it? You can see the code in action in JS Fiddle here. http://jsfiddle.net/w3fxtdq8/18/

Knockout.js foreach error

delirium TLDR: Knockout does not understand binding optionsin foreach context . I have the following HTML: <!-- ko foreach: getModelData(123).Filters.Products.ORDER --> <div class="row Filter"> <div class="col-7"> <select re

Knockout JS foreach $root undefined

quick shift I am trying to create a radio group in Knockout JS, here is the template code <p>Selected Plan <div data-bind="text: selectedPlan"></div></p> <div data-bind="foreach: plans"> <label> <input type="radio" name="plan" data-bind="attr: {val

Knockout JS foreach $root undefined

quick shift I am trying to create a radio group in Knockout JS, here is the template code <p>Selected Plan <div data-bind="text: selectedPlan"></div></p> <div data-bind="foreach: plans"> <label> <input type="radio" name="plan" data-bind="attr: {val

Foreach in foreach, two tables, Knockout.js

Igor Levashov This is the situation. I have two tables: Microsoft SQL product ProductId | ProductName __________|____________ 1 | iPhone5 2 | iPhone6 3 | iPhone6s picture Id | ImagePath | ProductId ___|__________________|_______

Foreach in foreach, two tables, Knockout.js

Igor Levashov This is the situation. I have two tables: Microsoft SQL product ProductId | ProductName __________|____________ 1 | iPhone5 2 | iPhone6 3 | iPhone6s picture Id | ImagePath | ProductId ___|__________________|_______

Foreach in foreach, two tables, Knockout.js

Igor Levashov This is the situation. I have two tables: Microsoft SQL product ProductId | ProductName __________|____________ 1 | iPhone5 2 | iPhone6 3 | iPhone6s picture Id | ImagePath | ProductId ___|__________________|_______

Knockout List: Exclude items from a sorted list

Joel I'm sorting a collection using elimination sort, and I have a "new" row that should always be empty and at the bottom of the list. I could cancel the drop "after this" by checking the position in the beforeMove, but it would be better if the area below th

Update list item with foreach Knockout binding

username There's a good example on the knockout website that uses foreach bindings to add and remove list items, but how would you update the values? I 've tried doing this in the fiddle below, but the DOM element doesn't respond to my updates : http://jsfiddl

Update list item with foreach Knockout binding

username There's a good example on the knockout website that uses foreach bindings to add and remove list items, but how would you update the values? I 've tried doing this in the fiddle below, but the DOM element doesn't respond to my updates : http://jsfiddl