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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:16:32+00:00 2026-06-16T00:16:32+00:00

I have a simple model for keeping my folders: var FolderModel = { folders:

  • 0

I have a simple model for keeping my folders:

var FolderModel = {
    folders: ko.observableArray([
        {id:'Global', uid: 'Global', name: 'Global', count:0}, 
        {id:'New', uid: 'New', name: 'New', count:0}, 
        {id:'Important', uid: 'Important', name: 'Important', count:0} 
    ]);

This model is binded to:

<ul class="folder-tree" data-bind="foreach: FolderModel.folders">
    <li>
        <span data-bind="text: $data.name"></span>
        <span class="count" data-bind="text: $data.count"></span>
    </li>
</ul>

So the initial view will be something like this:

  • Global (0)
  • New (0)
  • Important (0)

Then I’m doing some request polling in another script: waiting for the counts to change and update the model. Yet, nothing I’ve done worked. I have tried:

var match = ko.utils.arrayFirst(FolderModel.folders(), function (item) {
    return c == item.uid;
});

if (match) {
    match.count = counts[c];
}

c – here is the uid of the folder. So, I use arrayFirst, get the item in the observable array and update it.

The next thing I tried:

    $.each(FolderModel.folders(), function (index, folder) {
        var newFolder = FolderModel.folders()[index];
        newFolder.count = counts[folder.uid];
        FolderModel.folders.replace(FolderModel.folders()[index], newFolder);
    });

This also brought me nowhere and also looks quite silly, but I found this at another SO issue How to replace a given index element in knockoutjs

What am I doing wrong and what didn’t I get in the knockout.js? I was thinking that whener the observable arrays element gets modified and if it is data-binded to something, that something will be modified as well.

  • 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-16T00:16:33+00:00Added an answer on June 16, 2026 at 12:16 am

    You just need a folder to be a view model for Knockout to catch the changes or use observableArray methods to change the array:

    var Folder = function (id, uid, name, count) {
        // things that don't change don't need observables
        this.id = ko.observable(id);
        this.uid = ko.observable(uid);
        this.name = ko.observable(name);
        this.count = ko.observable(count);
    };
    
    var FolderModel = {
        folders: ko.observableArray([
            {id:'Global', uid: 'Global', name: 'Global', count:0}, 
            {id:'New', uid: 'New', name: 'New', count:0}, 
            {id:'Important', uid: 'Important', name: 'Important', count:0} 
        ])
    };
    
    var FolderModelNew = {
        folders: ko.observableArray([
            new Folder('Global', 'Global', 'Global', 0),
            new Folder('New', 'New', 'New', 0),
            new Folder('Important', 'Important', 'Important', 0)
        ])
    };
    
    var vm = {
        folderModel: FolderModel,
        folderModelNew: FolderModelNew
    };
    
    ko.applyBindings(vm);
    
    vm.folderModel.folders()[1].name = '111'; // nothing
    vm.folderModel.folders.splice(0, 1, {id:'Global', uid: 'Global', name: '000', count:0}); // updated
    vm.folderModelNew.folders()[1].name('111'); // updated
    ​
    

    Fiddle: http://jsfiddle.net/Sgc5J/

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

Sidebar

Related Questions

I have a simple model like this one: class Artist(models.Model): surname = models.CharField(max_length=200) name
I have a simple model like this: class Auction(models.Model): name = models.CharField() class Item(models.Model):
I have a simple model like this: class User < ActiveRecord::Base serialize :preferences end
I have simple item model with name and quantity: public class Item extends CouchDbDocument{
I have a simple model forms, that is being rendered through the following jinja2
I have a simple model class (Part), which pulls from it's information from a
I have a simple model containing a FileField among others. When I use a
I have a simple model from simulink and I would like to generate code
Suppose I have a simple model, such as Record: @Model public class Record {
I have a simple User model which is associated to many Town objects using

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.