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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:36:28+00:00 2026-06-02T10:36:28+00:00

I have just started with knockout this Model and viewmodel: $(function() { // Class

  • 0

I have just started with knockout this Model and viewmodel:

$(function() {

  // Class to represent a note
  function Note(title, content) {
    var self = this;

    self.title = ko.computed(function() {
  var title = title;
  if(title.length > 0) return title;

  if(self.content && self.content.length > 0) return self.content.substring(0,19) + "...";   
    });   

    self.content = ko.observable(content);

  }

  // Overall viewmodel for this screen, along with initial state
  function TaccuinoViewModel() {
    var self = this;

    // Editable data
    self.notes = ko.observableArray([
    ]);

    // Operations
    self.addNote = function() {
        self.notes.push(new Note());
    }
    self.removeNote = function(note) { self.notes.remove(note) }
  }

  ko.applyBindings(new TaccuinoViewModel());

});

The problem is with the computed property: what i want to do is:

1-)if title has a length > 0 use it
2-)in case it’s not defined use the first 20 charachters from content + “…”

but this doens’t work…

any suggestion about doing this, also in other ways?

  • 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-02T10:36:30+00:00Added an answer on June 2, 2026 at 10:36 am

    self.content is an observable, so you need to invoke it in order to get the current value:

    self.content = ko.observable(content);
    self.title = ko.computed(function() {
        if(title.length > 0) return title;
    
        var currentContent = self.content(); // <-- get the current value
        if(currentContent) return currentContent.substring(0,19) + "...";   
    });
    

    Note that I’ve moved the creation of the observable “content” to the top, because when creating a computed observable, its initial value gets computed once – so we may need the “content” observable to be present.

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

Sidebar

Related Questions

I just started using knockout.js and it works great with normal bidings. I have
I have just started working on localization of this application. Starting with three tab
I have just started using RadControls so this question might be basic for you,
I have just started to learn ASP.NET MVC 3 form this book and I
I have just started self-studying the Dragon book of Compiler Design. I am working
I have just started reading Modern C++ Design Generic programming and Design Patterns Applied
i have just started playing aorund with asp.net mvc and i want to view
We have just started out with Team Foundation Server 2008 / Visual Studio Team
I have just started coding in AS3 and it would be really great to
I have just started learning Jquery and am new to writing javascript (I am

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.