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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:59:41+00:00 2026-05-27T21:59:41+00:00

I have a template binding to an observableArray <ul data-bind=template: { name: ‘defaultTemplate’, foreach:

  • 0

I have a template binding to an observableArray

<ul data-bind="template: { name: 'defaultTemplate', foreach: itemsArray}"></ul>
...

And i need to refresh data each time by clicking a link

<a data-bind="click: LoadData"><span>Refresh</span></a>

The first version of my viewModel:

function viewModel (){  
    this.itmesArray = ko.observableArray([]);
    self = this;
    this.LoadData(){
        if('undefined' != typeof MusicArray )
            self.itmesArray.removeAll();
        LoadDataFromServerAsync(self.itmesArray);
    }   
    //ini
    LoadData();
    ...
}

But the problem is that the data is loaded from server in async, so when i click the link fast with little time interval, then the data may duplicate multi times in my obeservable array.
So i think i need load data to a new array in each refreshing.

Then the second version of viewModel:

function viewModel (){  
    this.itmesArray = ko.observableArray([]);
    self = this;
    this.LoadData(){
            if('undefined' != typeof MusicArray )
                self.itmesArray.removeAll();
            var tempArray = new Array();
            LoadDataFromServerAsync(tempArray);
            self.itmesArray(tempArray);
    }   
    //ini
    LoadData();
    ...
}

And the new problem is that the UI could not sense the changes of array, it seems self.itmesArray(tempArray) will construct a new observableArray object, but the template bindging is still tracking the old observableArray object, I’m not sure about this.
So i want to know how to notify the template/ui binding that my array has changed or is there any other workaround to fix my problem?

Added: Code on jsFiddle http://jsfiddle.net/zzcJC/10/

  • 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-27T21:59:41+00:00Added an answer on May 27, 2026 at 9:59 pm

    you can do as Gene suggest. for doing all on client side, you can create a helper object tha encapsulates the logic: it fires the requests, gets the responses, has an “abort” method to stop the request (if the user press “refresh” while still waiting for data), and updating the viewmodel only when all the data is arrived.

    I created a jsFiddle: http://jsfiddle.net/saurus/dE6S9/

    This uses “setTimeout()” to simulate ajax calls, stores the timeouts ids on an array (you would store the xhr returned by ajax calls), and calling “cancelTimeout()” to abort calls (you will use “xhr.abort or similar).

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

Sidebar

Related Questions

I have used the following template in my project: <DataTemplate x:Key=textBoxDataTemplate> <TextBox Name=textBox ToolTip={Binding
If I have a data template as follows, <DataTemplate DataType={x:Type vm:EditorTabViewModel}> <me:MarkdownEditor TextContent={Binding Path=Content,
I am running Django trunk and have template Autoescaping on (default). Do I need
I'm using a named template and binding a list of data to that. The
I have item template with image and textblock. And textblock binded to Name property.
I have a following ListView item template, in which I am trying to bind
I have a data template for my listbox and I must use project resources
I have a data template formatting items in a ListBox <DataTemplate x:Key=ChildViewModelTemplate> <Border BorderBrush=#FFDC1C1C
OK, I have a data template for items: <DataTemplate x:Key=SmallDayEventItemTemplate> <Border ...> <Grid ...>
I have template for my ComboBox . taken from here . Lets say each

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.