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

  • Home
  • SEARCH
  • 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 9219947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:14:03+00:00 2026-06-18T03:14:03+00:00

I have a computed property on my model which is just splitting a comma

  • 0

I have a computed property on my model which is just splitting a comma separated string into an array, and I want to be able to utilize the “checked” binding’s special array feature to write changes back through the computed property.

Everything works great for reading the computed property, but as soon as I check one of the checkboxes I get errors about some function not supporting splice (if I uncheck) or not supporting push (if I check).

> Uncaught TypeError: Object function
> h(){if(0<arguments.length)return"function"===typeof
> v?v.apply(d,arguments):j(Error("Cannot write a value to a ko.computed
> unless you specify a 'write' option. If you wish to read the current
> value, don't pass any parameters.")),this;n||g();b.r.Wa(h);return l}
> has no method 'splice' knockout-min.js:60 (anonymous function)

I created a quick sample on jsfiddle to illustrate what’s going on. http://jsfiddle.net/Y6tXw/

var MyModel = function() {
    this.src = ko.observable("one,two");
    this.comp = ko.computed({
        read: function() {
            return (this.src() || "").split(",");
        },
        write: function(value) {
            var csvs = (value || []).join(",");
            this.src(csvs);
        },
        owner: this
    });
};

var model = new MyModel();
ko.applyBindings(model);

It never calls my write function. It seems like it’s crashing in the binding. What am I doing wrong?

  • 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-18T03:14:04+00:00Added an answer on June 18, 2026 at 3:14 am

    comp in the above case in an computed, not an array. I have modified your code. I have used subscribe to listen to change notifications raised by comp and re-calculate the value of sec

    <input type="checkbox" value="one" data-bind="{ checked: comp }"/>
    <input type="checkbox" value="two" data-bind="{ checked: comp }"/>
    <input type="checkbox" value="three" data-bind="{ checked: comp }"/>
    <input type="text" data-bind="{ value: src }"/>
    
    
    var MyModel = function () {
    
        var self = this;
    
        self.src = ko.observable("one,two");
    
        self.comp = ko.observableArray((self.src() || "").split(","));
    
        self.comp.subscribe(function () {
            self.src(ko.utils.unwrapObservable(self.comp).join(","));
        });
    };
    
    $(function () {
        var model = new MyModel();
        ko.applyBindings(model);
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Person model, which includes a property representing the data of birth
I have my own User model in app engine, which should have a property
I have an ArrayController which is periodically updated. It has a sorted computed property
I have a simple model object with one array property. Example: {name: 'Foo', tags
I have a model with two property: title and content and what I want
I'm using Fluent NHibernate, and auto-mapping the classes. I have a computed property in
I have an controller which is an ArrayProxy and contains some computed arrays. In
Model: I have a model in which one Installation can contain multiple Computer Systems.
I want to model a kind of FSM(Finite State Machine). I have a sequence
How to add an computed column to the model class. I have two models

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.