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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:56:57+00:00 2026-06-16T21:56:57+00:00

I have an application that has the following setup (more or less): JS var

  • 0

I have an application that has the following setup (more or less):

JS

var ObjectVM = function(data) {
    var me = this;
    me.name = ko.observable(data.name);
    //Set other properties
    ...

    me.isSelected(false);
};
var VM = function () {
    var me = this;
    me.Records = [];
    me.Selected = ko.observable(undefined);
    me.Select = function (rec) {
        if (rec.hasChanges == undefined) {
            //attach editable functionality
            ko.editable(record);
        }
        rec.isSelected(true);
        rec.beginEdit();
        if (me.Selected() != undefined) {
            if (me.Selected().hasChanges()) {
                me.Selected().rollback();
            }
            me.Selected().isSelected(false);
            me.Selected().commit();
        }
        me.Selected(rec);
        //Do some hiding/showing of form...
    };
    me.Init = function(){
       $.ajax({...,
          success: function(data){
          for(var i = 0;i< data.length;i++){
           me.Records.push(new ObjectVM(data[i]));
          }
       }
    };
};

HTML

<div>
     RECORDS DISPLAY GRID (Pretend it's a table with 5 columns and 10 rows)
</div>
<div data-bind="with: Selected">
   <form id="editRec">
     <label>Name</label>
      <input data-bind="value: name" />
   </form>
</div>

I have a click binding setup on the table rows that calls VMs Select funciton. Using the “with” binding removes the form when Selected() is undefined and adds back when Selected() has a record. The issue that every time this occurs, I am losing my validation, tabs, and event bindings (non-KO bindings) that were attached to the form. The application functions perfectly, but with some performance hits when changing between records, as it is having to re-add the form, setup validation, ui config, and bindings.

Is there a way to have the form stay on the page, keeping my bindings and setup, or am I going to forced to deal with the hit every time the Selected value is changed?

  • 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-16T21:56:58+00:00Added an answer on June 16, 2026 at 9:56 pm

    Currently the with binding treats its contents as a template and re-renders any time the with value changes. The only way to avoid the re-rendering is to not use with.

    <div>
       <form id="editRec">
         <label>Name</label>
          <input data-bind="value: Selected().name" />
       </form>
    </div>
    

    Of course, if Selected can sometimes be undefined, this will not work, and you must look for another solution. The best one is to use a custom binding that sets up your event handlers, validation, tabs, etc.

    <!--ko with: Selected-->
    <div data-bind="setUpStuff: true">
       <form id="editRec">
         <label>Name</label>
          <input data-bind="value: name" />
       </form>
    </div>
    <!--/ko-->
    

    A third alternative to avoid some re-rendering and also support an undefined value is to use Knockout 2.2 and the if binding (and avoid with). In 2.2, the if binding will only re-render if the value goes falsy to truthy, but not if it changes from one truthy value to another.

    <!--ko if: Selected-->
    <div data-bind="setUpStuff: true">
       <form id="editRec">
         <label>Name</label>
          <input data-bind="value: Selected().name" />
       </form>
    </div>
    <!--/ko-->
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a Zend application that has these following modules: Users Shop etc... Front
I have an application that has 2 beans with the same name, but which
I'´m currently twiddling with an application that has a setup matching the following chat
We have an application that has a database full of polygons (currently stored as
I have a application that has an activity that shows message logs. The thing
I have an application that has two localization options at the moment through .resx
I have an application that has two threads. The first one (the main thread)
i have an application that has a dependancy on gdiplus. i need the application
I have an application that has a list of buttons and has customized tooltips.
I have an application that has a .sql file in it. The sql file

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.