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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:05:56+00:00 2026-06-02T19:05:56+00:00

I have a model with two property: title and content and what I want

  • 0

I have a model with two property: title and content and what I want to do is:

If title has a value, use it but in case it’s blank use the first 20 chars + “…” from content.

This is the model:

       function Note(title, content) {
        var self = this;

        self.content = ko.observable(content);
        self.title = ko.computed({
          read: function(){
            if(!title){
              var content = self.content();
              if(content) return content.substring(0,19) + "...";
            }
          },
          write: function(title){
           return title;
          }
        });
       }

Title value gets correctly updated from content but it’s impossible (for me) to get writing directly on title working..

The only problem in RP Niemeyer answer is that i must have only on property for reading/writing, is that possible?

  • 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-02T19:05:58+00:00Added an answer on June 2, 2026 at 7:05 pm

    When creating your writeable computed observable, you will want to have a separate observable to contain the actual title.

    More like:

    function Note(title, content) {
        var self = this;
    
        self.content = ko.observable(content);
        self.title = ko.observable(title);
    
        self.displayTitle = ko.computed({
            read: function() {
                var title = self.title();
                if (!title) {
                    var content = self.content();
                    if (content) return content.substring(0, 19) + "...";
                }
    
                return title;
            },
            write: self.title
        });
    }​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two model classes, say parent and child. Parents are created first, and
I have a Core Data model with two entities: A and B. A has
I have a model with an enum property (in this case, related to Export
I have two model: User, Article A user can like or dislike many articles,
I have two questions. 1: At the moment I have two model classes that
I have a hibernate model with two classes, let's say A and B. B
I have a Profile model and two ActiveRecord::Relations of this model. SQL request of
I have a simple data model of two tables, email and recipients, email can
I have a Django model TimeThingie with two TimeField s called t1 and t2
I have a simple Fluent NHibernate model with two related classes: public class Applicant

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.