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

  • Home
  • SEARCH
  • 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 7444749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:34:49+00:00 2026-05-29T11:34:49+00:00

I am mostly wondering how to organize things like modal windows, and dynamic pages

  • 0

I am mostly wondering how to organize things like modal windows, and dynamic pages like profiles. Should the viewModel only contain one profile view or contain all profiles loaded? This here just doesnt seem very “clean”.

viewModel = {
  profile: ko.observableArray([
    new ProfileViewModel()
    //... any others loaded
  ])
, createPostModal: {
    input: ko.observable()
  , submit: //do something to submit...
  }
}

<div data-bind="foreach: profile"><!-- profile html --></div>
<div data-bind="with: createPostModal"></div>

This way doesn’t seem very consistent. Is there anybody who has built a single page app with knockout that can offer some advice? Code samples would be appreciated.

  • 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-05-29T11:34:50+00:00Added an answer on May 29, 2026 at 11:34 am

    We are just starting down this path at work, and so are not quite sure what we’re doing. But here’s the idea we have.

    The page should be composed of any number of “components,” possibly nested. Each component has a view model and one public method, renderTo(el), which essentially does

    ko.applyBindings(viewModelForThisComponent, el)
    

    It also could have the ability to render subcomponents.

    Constructing or updating a component consists of giving it a model (e.g. JSON data from the server), from which it will derive the appropriate view model.

    The app is then created by nesting a bunch of components, starting with a top-level application component.


    Here is an example for a “hypothetical” book-managing application. The components are LibraryUI (displays a list of all book titles) and DetailsUI (a section of the app that displays details on a book).

    function libraryBookViewModel(book) {
      return {
        title: ko.observable(book.title),
        showDetails: function () {
          var detailsUI = new BookDetailsUI(book);
          detailsUI.renderTo(document.getElementById("book-details"));
        }
      };
    }
    
    function detailsBookViewModel(book) {
      return {
        title: ko.observable(book.title),
        author: ko.observable(book.author),
        publisher: ko.observable(book.publisher)
      };
    }
    
    function LibraryUI(books) {
      var bookViewModels = books.map(libraryBookViewModel);
      var viewModel = {
        books: ko.observableArray(bookViewModels);
      };
    
      this.renderTo = function (el) {
        ko.applyBindings(viewModel, el);
      };
    }
    
    function BookDetailsUI(book) {
      var viewModel = detailsBookViewModel(book);
    
      this.renderTo = function (el) {
        ko.applyBindings(viewModel, el);
      };
    }
    

    Note how we could make the book details appear in a jQuery UI dialog, instead of in a singleton #book-details element, by changing the showDetails function to do

    var dialogEl = document.createElement("div");
    detailsUI.renderTo(dialogEl);
    $(dialogEl).dialog();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if this was possible. Mostly I want to understand what GNOME
Just something that i was wondering about. In Europe the comma us mostly used
I have a Python program that is mostly complete, and there is one thing
I am trying to create a table like the one where you choose your
I am using EclipseCORBA, but mostly just for syntax highlighting. I'm wondering if there
I do mostly Windows development. We use Mantis and Subversion for our development but
I have an application that mostly works, but am having one condition wherein the
I was wondering how I could do this. I'm mostly puzzled by the N
I'm wondering how multiple pointers should/could be handled by a high level application. I'm
I am wondering if there are any android device databases around. One of the

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.