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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:28:13+00:00 2026-05-31T09:28:13+00:00

Here is my simplified model: var GoalItem = function(id, type, name, authorId, author, children)

  • 0

Here is my simplified model:

        var GoalItem = function(id, type, name, authorId, author, children) {
        this.id = ko.observable(id);
        this.type = ko.observable(type);
        this.name = ko.observable(name);     
        this.authorId = ko.observable(authorId);
        this.author = ko.observable(author);
        this.children = ko.observableArray(children || []);
        this.isPage = ko.computed(function(){ return type == 'page' ? true : false; }, this);
        this.isFile = ko.computed(function(){ return type == 'file' ? true : false; }, this);
        };

        var GoalModel = function() {
        this.list = ko.observableArray([
            new GoalItem(1, 'page', 'Getting started', 0, '', [
                new GoalItem(2, 'page', 'Getting started 1.1', 0, ''),
                new GoalItem(3, 'video', 'Video', 0, '', [
                    new GoalItem(4, 'data', 'Data', 0, ''),
                    new GoalItem(5, 'test', 'Test', 0, '', [
                        new GoalItem(6, 'page', 'Test prep', 0, '', [
                            new GoalItem(7, 'video', 'Test video', 0, ''),
                            new GoalItem(8, 'file', 'Test file', 0, '')
                        ])
                    ]),
                    new GoalItem(9, 'page', 'Sample page', 0, '')
                ])
            ]),
            new GoalItem(10, 'page', 'More data tracking', 0, '', [
                new GoalItem(11, 'data', 'Data 1', 0, ''),
                new GoalItem(12, 'data', 'Data 2', 0, '')
            ])
        ]);
        }

and some markup uses isvisible to determine which pieces of html to show

<div data-bind="visible: currentItem().isPage">
    applicable to pages only
</div>

vs.

<div data-bind="visible: currentItem().isFile">
    applicable to files only
</div>

I have some code that when a user clicks on a GoalItem which is rendered into a treeview will load and the isvisible will take care of show/hide

If the user now makes a change in the UI for the “type” property of the current GoalItem should that not re-trigger the isvisible – so if type changes from “page” to “file”

Currently it does not appear to be working, hopefully this explanation makes sense, if not I will try to add more detail.

On another note, from reading, would i instead have to “remove” or “replace” the item in the observable array in order to get it to re-trigger the isvisible: binding”? – and if so – or as a related question – what is the best way to find an item in observableArray based on the this.id – baring in mind that the item can be “deep” within the children?

any feedback or help is greatly appreciated

  • 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-31T09:28:15+00:00Added an answer on May 31, 2026 at 9:28 am

    You computed observables will trigger UI updates, but they are not quite correct:

        this.isPage = ko.computed(function(){ return type == 'page' ? true : false; }, this);
        this.isFile = ko.computed(function(){ return type == 'file' ? true : false; }, this);
    

    These should look more like:

        this.isPage = ko.computed(function() { 
            return this.type() == 'page' ? true : false; 
        }, this);
    
        this.isFile = ko.computed(function() { 
            return this.type() == 'file' ? true : false; 
        }, this);
    

    Now, you have actually accessed the observable’s value, so the computed observable has a dependency on the type observable. When it changes (by setting its value like this.type('file');, the computed observable will be re-evalauted and any subscribers (your UI) will be notified.

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

Sidebar

Related Questions

Here is a simplified version of my database model. I have two tables: Image,
Here is a simplified version of one of my models: class ImportRule(models.Model): feed =
I've got 3 tables that are something like this (simplified here ofc): users user_id
I'm currently doing a firewall management application for Django, here's the (simplified) model :
Here is my data model (simplified), public class AddressBook { private List<Group> groups =
Here's my (simplified) model: Ticket -> Customer Callback (s) I have my Ticket mapped
This model is simplified, only used for demonstration. In my application got: Data public
Is there any way to get this to work? Here's a simplified/contrived illustration of
Here is simplified version of my requirement I have a java class say Processor
I want to list all users with their corropsonding user class. Here are simplified

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.