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 8915337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:57:17+00:00 2026-06-15T04:57:17+00:00

The question: How can I structure my code so that the knockout bindings are

  • 0

The question: How can I structure my code so that the knockout bindings are not applied until all of the queries for the ViewModel have been executed?

Update: After some further research and experimentation I think that using something along the lines of a Deferred function may work. I have tried a few implementations, however it only defers until the query is called, rather than until all query results have been processed. I’m obviously doing something wrong here but my javascript foo is weak.

Technologies used: Entity Framework 5 w/ Oracle, .Net 4 Web API, Knockout 2.2, Breeze 0.71.3

The situation: Breeze is being used to call a Web API method which retrieves an Enumerable of POCOs, populates a knockout observable array, and the array is bound to a select control in the View.

The problem: The breeze queries have not completed and the knockout observables have not been populated prior to applying the ViewModel bindings to the View. When the query results are returned, the UI is unresponsive for 5 – 7 secs while the ko observable is populated and thus the select control is updated.
Based on the logging this appears to be the issue…

The cshtml file:

<select data-bind="options: $root.brokers, value: 'id', optionsText: 'name'">
<script data-main="/BrokerCommission/Scripts/app/main" src="/BrokerCommission/Scripts/require.js"></script>

main.js:

requirejs.config(
    {
        // well-know paths to selected scripts
        paths: {
            'breeze': '../breeze.debug', // debug version of breeze
            'text': '../text'// html loader plugin; see http://requirejs.org/docs/api.html#text
        }
    }
);

define(['logger', 'text', 'breeze'], function(logger) {

require(['vm.muni'],
function()
{
    logger.info('applying bindings');
    ko.applyBindings(my.vm);
});

vm.muni is my ViewModel javascript file. Here’s a method being exposed to exec a query:

getAllBrokers = function () {
        dataservice.getBrokers()
            .then(processBrokerQueryResults)
            .fail(handleQueryErrors);
    },

    processBrokerQueryResults = function (data) {
        logger.info("Start loading Brokers " + Math.round(new Date().getTime() / 1000));
        my.vm.brokers([]);
        $.each(data.results, function (i, d) {
            brokers.push(new my.Broker()
                .id(d.id)
                .name(d.name)
            );
        });
        logger.info("End loading Brokers " + Math.round(new Date().getTime() / 1000));
    },

Here is the breeze query from dataservice.js file:

function getBrokers() {
    var query = new entityModel.EntityQuery()
            .from("GetBrokers")
            //.orderBy("name");
    return manager.executeQuery(query);
};
  • 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-15T04:57:18+00:00Added an answer on June 15, 2026 at 4:57 am

    A few thoughts occur to me:

    1. I rarely push one-by-one into the observableArray. Too many DOM updates. Create a temporary array instead and update the observableArray with that. I believe this is the answer to the performance problem you’re asking about.

    2. Set up an initialize method that returns a promise when all initial async load methods complete.

    3. Delay ko.applyBindings until the initialize promise resolves successfully.

    4. Consider showing a splashscreen + spinner while waiting for initialization to finish.

    5. Try not to do too much during initialization.

    I can’t show you how to do every one of these things in this answer. I’ll show you #1 here and refer you "Fetch on Launch" in the documentation for #2. Web search + experimentation are your friends for the rest.

    Update observableArray with an array

    processBrokerQueryResults = function (data) {
            ...
            var tempArray = []
            $.each(data.results, function (i, d) {
                tempArray.push(dtoToBroker(d));
            });
            brokers(tempArray);
            ...
    
            // I prefer named fns to long lambdas
            function dtoToBroker(dto) {
               return new my.Broker()
                      .id(d.id)
                      .name(d.name);
            }
    

    I like to use the ECMAScript 5 Array.map syntax which returns an array after applying a function to each element of a source array. So I’d write:

    processBrokerQueryResults = function (data) {
            ...
            brokers(data.results.map(dtoToBroker));
            ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my other question You can see code of my arr structure and PriorityQueue
Lately I've been writing FFI code that returns a data structure in the IO
This question might be a bit sketchy because I do not have the code
I have a C\C++ code that receives a structure over the network, from this
I know this question can be answered by searching in google. But I have
I am trying to adapt the underlying structure of plotting code (matplotlib) that is
Can anyone point to some code that deals with the security of files access
Here is my code structure, that I saw from someone else and am trying
Let's say we have a Windows app that has a TreeView and you can
i have a bit of code that i wrote a few weeks ago (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.