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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:48:34+00:00 2026-05-31T14:48:34+00:00

I have a semi-comprehensive KO setup. But so far I have only used KO

  • 0

I have a semi-comprehensive KO setup. But so far I have only used KO to present the data.

Now I have a need to increase/decrease values on my model.

Here’s my Model:

SharedItem: function (data) {
    var self = {};
    ...
    self.rating = ko.observable(data.Rating);
    ...
    return self;
}

And here’s my View

ItemsViewModel: function (json) {
    var model = {};
    model.shareditems = ko.observableArray();

    var mappedSharedItems = [];
    var parsedData = $.parseJSON(json);

    $.each(parsedData, function (key, val) {
        var newSharedItems = new SharedItem(val);
        mappedSharedItems.push(newSharedItems);
    });

    //My function to vote
    model.voteUp = function(item) {
        item.rating += 1;
    }

    model.shareditems(mappedSharedItems);
    return model;
}

And my view is applied like any standard Knockout binding (response is my ajax response that I pass to the viewmodel):

var viewModel = ItemsViewModel(response);
ko.applyBindings(viewModel, $('#ItemListWrapper')[0]);

But I can’t seem to figure out how to make my voteUp function increase the rating number.

And important note: The rating value is a string, from the server. But I guess I could be able to just use parseInt on it.

Can anyone point my in a direction on how to make this function increase a value of the model’s property?

Thanks in advance

Edit: If you want to see the HTML where I call voteUp here it is:

<div class="Vote">
    <a href="#" data-bind="click: $parent.voteUp">+1</a>
</div>

Edit 2: My solution:

item.rating(parseInt(item.rating()) + 1);

  • 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-31T14:48:36+00:00Added an answer on May 31, 2026 at 2:48 pm

    You need to use the observable syntax to do this:

    model.voteUp = function(item) { item.rating(item.rating() + 1); }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used XDebug semi-sucessfully with PhpStorm and Mamp, but now I want to
I have a file which is similar to /etc/passwd (semi-colon separated values), and need
I have a semi-large web application that we run locally and I need to
I have a dilema, I want to present to the user a semi-transparent view.
I have a semi-melted data frame that looks like this: head(final_melt) Group Source variable
We have semi-complicated expressions in the format: 25 + [Variable1] > [Variable2] We need
I have a navigation bar with a semi-transparent background but the navigation links are
I have a long list of Unicode values that are semi-colon delimited. Here's an
We have a semi-weird issue for our site. Consistently, from 1 anonymous* user the
Okay so i have a semi weridish problem with re.sub. Take the following code:

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.