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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:38:08+00:00 2026-06-08T15:38:08+00:00

In a web app based on Knockoutjs and Sammy.js I have three observables that

  • 0

In a web app based on Knockoutjs and Sammy.js I have three observables that depend on each other in a parent-child way (the second is child of the first, the third is child of the second). My HTML has three sections where only one should be visible at a time. Each section depends on one of the mentioned observables using the visible binding.

My URL scheme is laid out like /#id-of-parent/id-of-child/id-of-grandchild (in Sammy.js).

If I access a full URL (one with all three ids) I get into trouble with the observables. In the Sammy rule function I first load and store the parent, then the child and lastly the grandchild (which is really the data the user wants to see). The problem is that the bindings for the parent and the child are also triggered.

Is there a way to avoid triggering the bindings or is there a better way to organise an app like this?

Here are my Sammy routes:

Sammy(function() {
  this.get('#study/:id', function() {
    self.studylist(null);
    self.currentStudy(Study.loadById(this.params.id));
  });

  this.get('#study/:id/variableGroups', function() {
    self.variableGroupList(self.currentStudy().variableGroups());
    self.currentVariable(null);
  });

  this.get('#study/:id/variable-group/:variableGroup/variables', function() {
    var groupId = this.params.variableGroup;
    $.ajax(apiUrl + "/variable-group/" + groupId, {
      type: "GET",
      async: false,
      cache: false,
      context: this,
      success: function(data) {
        if (!self.currentStudy()) {
          self.currentStudy(Study.loadById(this.params.id));
        }
        self.currentVariableGroup(new VariableGroup(data.variablegroup));
        self.variableList(self.currentVariableGroup().variables);
      }
    });
  });

  this.get('#study/:id/:variableGroupId/:variableId', function() {
    var variableId = this.params.variableId;
    $.ajax(apiUrl + "/variable/" + variableId, {
      type: "GET",
      async: false,
      cache: false,
      context: this,
      success: function(data) {
        if (!self.currentStudy()) {
          self.currentStudy(Study.loadById(this.params.id));
        }
        if (!self.currentVariableGroup()) {
          self.currentVariableGroup(VariableGroup.loadById(this.params.variableGroupId));
        }
        self.currentVariable(new Variable(data.variable));
      }
    });
  });

  this.get("", function() {
    self.currentStudy(null);
    self.currentVariableGroup(null);
    self.currentVariable(null);
    $.get(apiUrl + "/study/all", function(data) {
      var mappedStudies = $.map(data.studies, function(item, index) {
        return new Study(item);
      });
      self.studylist(mappedStudies);
    });
  });

  this.get('', function() { this.app.runRoute('get', "")});

}).run();
  • 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-08T15:38:10+00:00Added an answer on June 8, 2026 at 3:38 pm

    I don’t think this is possible, and with good reason. It violates the principles of data-binding to update a subscribable without notifying subscribers. I strongly encourage you to refactor your program so that updating currentStudy and currentVariableGroup doesn’t cause unwanted side effects. Let some other factor determine the desired effect, perhaps an activeTemplate observable.

    In any case, here is the source code for observable. Note that the inner value is a private member and cannot be accessed from outside. It can only be set by calling the observable (which notifies subscribers).

    ko.observable = function (initialValue) {
        var _latestValue = initialValue; //Value is in closure, inaccessible from outside
    
        function observable() {
            if (arguments.length > 0) {
                // Write
    
                // Ignore writes if the value hasn't changed
                if ((!observable['equalityComparer']) || !observable['equalityComparer'](_latestValue, arguments[0])) {
                    observable.valueWillMutate();
                    _latestValue = arguments[0];
                    if (DEBUG) observable._latestValue = _latestValue;
                    observable.valueHasMutated();
                }
                return this; // Permits chained assignments
            }
            else {
                // Read
                ko.dependencyDetection.registerDependency(observable); // The caller only needs to be notified of changes if they did a "read" operation
                return _latestValue;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP-based web app that I'm trying to apply Apache's mod_rewrite to.
I have a mod_perl2 based web app that requires a connection to a mysql
I have PHP based web app that does calculations on a series of numbers
I have a php based web app that on a user entering a value,
I'm writing a web-based app from scratch, that needs PDF generation capabilities. All other
I have a split view controller-based iPad app that uses a Web View to
I'm working on a MVC based web app on LAMP that needs some records
I'm developing an intranet-based web app that integrates with Facebook via the Graph API.
Scenario: I build a simple web based app for mobile that needs to interact
In our Pylons based web-app, we're creating a class that essentially provides some logging

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.