Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

99
Visualizações
Foreach in foreach calling knockout.js

I was trying to find on similar posts solution, but mine attempts dont work.

Idea: Simply I have Services and ServiceTypes. I packed it in my MVC controller method like this:

public class SimpleGroupedService
{
    public int ServiceTypeId { get; set; }
    public string ServiceTypeName { get; set; }
    public List<SimpleServiceDTO> GroupedServices { get; set; }
}

Im passing to my js the whole object as services. So the object services contains also GroupedServices object which is a list.

object services

Problem: In my html I'm trying foreach within foreach loop, and first level of services is ok, it shows serviceTypeName correctly, however, second foreach is broken.

<section class="list-container">
    <div>
        <!-- ko foreach: services -->
        <header>
            <i class="icon-employee"></i>
            <span data-bind="text: $root.shell.substring(ServiceTypeName, 200)"></span>
        </header>
        <ul>
            <li><a href="" data-bind="text: $root.GroupedServices"></a></li>
        </ul>
        <!-- /ko -->
    </div>
</section>

Error shown: I dont have any errors in my console log unless I put something like this data-bind="text: $root.GroupedServices.Name"

then I have an error:

knockout-3.2.0.js?v=1.7.2:63 Uncaught TypeError: Unable to process binding "text: function(){return $parent.GroupedServices.Name }"
Message: Cannot read properties of undefined (reading 'Name')
    at text (eval at parseBindingsString (knockout-3.2.0.js?v=1.7.2:59), <anonymous>:3:88)
    at update (knockout-3.2.0.js?v=1.7.2:88)
    at a.j.o (knockout-3.2.0.js?v=1.7.2:63)
    at k (knockout-3.2.0.js?v=1.7.2:42)
    at Object.a.s.a.j (knockout-3.2.0.js?v=1.7.2:45)
    at knockout-3.2.0.js?v=1.7.2:63
    at Object.u (knockout-3.2.0.js?v=1.7.2:10)
    at f (knockout-3.2.0.js?v=1.7.2:62)
    at h (knockout-3.2.0.js?v=1.7.2:60)
    at g (knockout-3.2.0.js?v=1.7.2:60)
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda