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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:33:47+00:00 2026-06-14T21:33:47+00:00

here is what I need to accomplish in short: ‘dynamically change the style, based

  • 0

here is what I need to accomplish in short: ‘dynamically change the style, based on computed value change’

I have an observable array with initial set of,let say, 3.

I do use a template with each element from the array going into a separate div (I float them to the left in css)

<script type="text/html" id="feedsTemplate">
<div style="float:left;" data-bind="style: { width: $root.CurrentColumnWidth()+'px'}">
    <strong data-bind="text: SearchTerm"></strong>
</div>
</script>

here is my viewModel:

var viewModel = {
    Feeds: ko.observableArray([
        new Feed("Boston"),
        new Feed("NewYork"),
        new Feed("Chicago", ),
    ]),

    GetLatestFeeds: function () { getLatestFeeds(); },
    FeedsCounter: ko.observable(3),
    CurrentColumnWidth:  ko.computed (function()
    {           
        return ((GetCurrentPageWidth() / this.FeedsCounter));
    },this)
};

depending on the number of elements in that array, I calculate the width of the div where each of the element will be placed.
(I tried not to use the counter and refer directly to the viewModel.Feeds.length, but it seems there is no length in observableArray)

The problem I have is that after the number of elements in Feeds increased, due to the updates from the server, there is no recalculation happens for the div width.
here is update function:

function getLatestFeeds()
{

    $.getJSON('/Feed/GetUpdatedFeeds', function (data)
    {
        $.each(data, function ()
        {
            viewModel.Feeds.push(new Feed(this.SearchTerm, this.FeedItems));
            viewModel.FeedsCounter = viewModel.FeedsCounter + 1;
        });
    });
}

as far as I understand, from http://www.knockoutjs.com:
“… and they will be updated whenever firstName or lastName changes (your evaluator function will be called once each time any of its dependencies change, and whatever value you return will be passed on to the observers such as UI elements or other computed observables).”

whenever FeedsCounter changes, the computed var is updated too, and as I have it bounded to the div’s css, with width should change as well.. That just does not happen.

will appreciate any help/suggestions/pointers.

Thanks!

  • 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-14T21:33:48+00:00Added an answer on June 14, 2026 at 9:33 pm

    When you get value from observable you should use () because it is a function. The same for setting values:

    var viewModel = {
        Feeds: ko.observableArray([
            new Feed("Boston"),
            new Feed("NewYork"),
            new Feed("Chicago", ),
        ]),
    
        GetLatestFeeds: function () { getLatestFeeds(); },
        FeedsCounter: ko.observable(3),
        CurrentColumnWidth:  ko.computed (function()
        {           
            return ((GetCurrentPageWidth() / this.FeedsCounter()));
        },this)
    };
    
    function getLatestFeeds() {
    
        $.getJSON('/Feed/GetUpdatedFeeds', function (data)
        {
            $.each(data, function ()
            {
                viewModel.Feeds.push(new Feed(this.SearchTerm, this.FeedItems));
                viewModel.FeedsCounter(viewModel.FeedsCounter() + 1);
            });
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried this JavaScript but it doesn't work - here I need to change
Short version of what I want to accomplish : I have a foot pedal
Here's rough example of what I need to accomplish for better understanding: SampleTable PrimaryKey
I have an array of rows from a database I need to sort by
I'm converting an existing program to C++ and here need to manipulate Sybase timestamps.
Here I need to call a javascript function first and after some time I
Here i need to check a button click using javascript i.e)if button A is
here i need a batch file which can apply and create label or base
I'm stuck here: I need to get the values of org.jboss.system.server.ServerInfo With the code
hi i am doing one application here i need to disply 6 images in

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.