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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:25:09+00:00 2026-06-08T19:25:09+00:00

I’m new to knockout and don’t know if I’m doing this right at all

  • 0

I’m new to knockout and don’t know if I’m doing this right at all or not

I have a shopping cart editor, just like knockout live examples, except the fact that I want to have a more advanced product selector. my products have actually two kind of code which user must be able to enter one of those and get product’s complete details on his cart. so I would have two inputs for each kind of code and when the user enter a code in any of those, I should make an ajax call and load product info (including productId, productName, the_other_code, etc.).

I’v tried to this by subscribing to both code1 & code2 – make ajax call and set model’s data after getting data from the server, but it makes a kind of recursive event(subscribe) firing and thus calling ajax methods repeatedly.thus I believe if can set knockout subscription OFF during the SetData method, then the recursive act would not happens.

function Product(data) 
{
    var self = this;

    self.ProductId = ko.observable();
    self.Code1 = ko.observable();
    self.Code2 = ko.observable();
    self.Title = ko.observable();

    self.SetData = function (itemdata) {
        self.ProductId (itemdata ? itemdata.ProductId : null);
        self.Code1(itemdata ? itemdata.Code1 : null);
        self.Code2(itemdata ? itemdata.Code2 : null);
        self.Title(itemdata ? itemdata.Title : null);
    };

    self.SetData(data);

    self.Code1.subscribe(function (value) 
    {
        var productInfo = Ajax_GetPartDataWithCode1(value);
        self.SetData(productInfo );
    });

    self.Code2.subscribe(function (value) {
        var productInfo = Ajax_GetPartDataWithCode2(value);
        self.SetData(productInfo );
    });
}

any help would be greatly appricated!

  • 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-08T19:25:11+00:00Added an answer on June 8, 2026 at 7:25 pm

    A simple boolean flag should be enough. Set it to true upon entering SetData and to false when exiting, then in the subscribe callbacks return right away if the flag is set:

        var updatingData = false;
    
        self.SetData = function (itemdata) {
            updatingData = true;
            self.ProductId (itemdata ? itemdata.ProductId : null);
            self.Code1(itemdata ? itemdata.Code1 : null);
            self.Code2(itemdata ? itemdata.Code2 : null);
            self.Title(itemdata ? itemdata.Title : null);
            updatingData = false;
        };
    
        self.SetData(data);
    
        self.Code1.subscribe(function (value) 
        {
            if (updatingData) return;
            var productInfo = Ajax_GetPartDataWithCode1(value);
            self.SetData(productInfo);
        });
    
        self.Code2.subscribe(function (value) {
            if (updatingData) return;
            var productInfo = Ajax_GetPartDataWithCode2(value);
            self.SetData(productInfo);
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6
I know there's a lot of other questions out there that deal with this

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.