Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9153117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:12:41+00:00 2026-06-17T12:12:41+00:00

What I am trying to achieve is for the LoadVenues() function to populate a

  • 0

What I am trying to achieve is for the LoadVenues() function to populate a nested foreach template:

I have an array of Providers which has a Provider.ProviderVenues collection – I don’t want ProviderVenues populated for every Provider. I want the user to able to click a Provider and then have the ProviderVenues collection for the clicked provider populated ‘on demand’.

I have a knockout foreach template of ‘providers’, as loaded from a web service.

<tbody data-bind="foreach: {data: providers}">

The template lists each Provider and each includes a link which when clicked expands a Bootstrap Accordion and calls a ViewModel function LoadVenues()

<td>
    <a href="#"  data-toggle="collapse" data-bind="attr: { 'data-target': DomId }, click: $parent.LoadVenues">Click to expand and see Venues</a>

    <div data-bind="attr: { 'id': Id }" class="collapse" >
        Venues list:                                            
        <ul data-bind="foreach: {data: ProviderVenues}">
            <li data-bind="text: Name"></li>
        </ul>

    </div>
</td>

and in the ProvidersViewModel…

function providersViewModel() {
    var obj = {};

    obj.providers = ko.observableArray();

    function loadProvidersFromSvc() {
        var url = '/api/providersvc/GetAllProviders';   
        $.getJSON(url,
            function (data) {            
                obj.providers.removeAll();
                var results = ko.observableArray();
                ko.mapping.fromJS(data.Records, {}, results);
                for (var i = 0; i < results().length; i++) {
                    obj.providers.push(results()[i]);
                };
            }
        );
    };

    function loadVenues(record) {
      alert('clicked ' + record.Id());
      //todo: call $.getJSON, get Venues by Provider Id and somehow get this data into the nested template.
    }

    obj.LoadVenues = loadVenues;
}

What I really want loadVenues() to do is pull Venue data from the webservice by Provider Id (which I can do) and bind the retrieved ProviderVenues data to the nested template that was clicked.

I’m totally baffled as to how to do this and think I might be going the wrong way. Can somebody please point me in the right direction?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:12:42+00:00Added an answer on June 17, 2026 at 12:12 pm

    Move the LoadVenues function to the ProviderViewModel since it belongs there, and just load the observableArray from there. If you really, really need todo from the parent the click handler takes the clicked viewmodel as argument so you can load the array using the reference

    Example on the parent approach
    

    http://jsfiddle.net/kMvGp/1/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have trying to achieve a url rewrite which can be fairly simple but
im trying to achieve something but i dont really know how I have set
im trying to achieve the following, in php i have a form like this:
Trying to achieve the drop down effect I have on my form here once
What I am trying to achieve is the following: I want to have numerous
I am trying to achieve: foreach (ScheduleItem s in ScheduleItems) { foreach (IScheduleModule m
I am trying to achieve the following. I have a dozen divs with something
Im trying to achieve the following: A certain page will have a series of
Im trying to achieve a design that has five columns with fluid width, but
Im trying to achieve the effect like Safari on Mac and iPad have with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.