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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:48:09+00:00 2026-06-15T22:48:09+00:00

I have javascript code block and html like below. The model object is a

  • 0

I have javascript code block and html like below. The model object is a generic.
It is defined at run time.

It can be like this.

var model = { "xId": ko.observable(0), "xName": ko.observable(null), "Type": ko.observable("x") };
   /* var model = { "yId": ko.observable(0), "yName": ko.observable(null), "Type": ko.observable("y") };
    var model = { "zId": ko.observable(0), "zName": ko.observable(null), "Type": ko.observable("z") };  */

    var vm = function (data) {
        ko.mapping.fromJS(data, {}, this);
    };

    var vm2 = function () {
        var self = this;
        self.New = ko.observable(null);
        self.NewItem = function () {
            console.log(model);
            self.New(new vm(model));
        };
    };

    var viewModel = new vm2();
    ko.applyBindings(viewModel);

    vm.prototype.Save = function () {
        viewModel.New(null);
        /*In here all of inputs must be cleared but How to :)*/
    };

The newForm for first model.

<input type="button" data-bind="click: NewItem" value="Add" />
<div data-bind="with:New" id="newForm">
    <input type="text" data-bind="value:xId" />
    <input type="text" data-bind="value:xName" />
    <input type="text" data-bind="value:Type" />
    <input type="button" data-bind="click: Save" value="Save" />
</div>

I click the add button, then I tpye sometings to inputs, then I click the save button.
The newForm is invisible. So far everything is ok. But I click the add button again, I had written values ​​are still in the inputs. I can’t clear the newForm after save.

EDIT:

public class Test{
    public int TestId {get; set;}
    public int TestName {get; set;}
}

public class Test2{
    public int Test2Id {get; set;}
    public int Test2Name {get; set;}
}

The coutn of entity classes is not clear.

My entity classes is converted json. the model is create by .net like this.
My project have a master page and subpages.
for test page :

var model = <%=ViewModelCreator.Create<Test>() %>;

for test2 page :

var model = <%=ViewModelCreator.Create<Test2>() %>;
  • 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-15T22:48:10+00:00Added an answer on June 15, 2026 at 10:48 pm

    edit: Your viewmodel is a bit strange, having that inner model that is a static reference to the same observables, the mapping plugin will reuse old observables when they find them. Why are you even mapping like that to a static defined collection of observables, why not just explicit declare your viewmodel?

    Old answer
    Could do it?

    for(var index in vm) {
       if(ko.isObservable(vm[index])) {
          vm[index](null);
       }
    }
    

    edit: You could also create a special observable that is clearable

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

Sidebar

Related Questions

I have a JS code like this <script type=text/javascript> $(document).ready(function(){ $('.main').on('click', '.block', function (){
i have html code block like this <div id=some-div> <a href=# class=link-click>some link text</a>
I have javascript code some thing like this -- var count=3; var pl=new Array(count);
I have javascript code embedded inside a html template file. When I load this
I have this Javascript code I inherited from another developer. I am very new
If I have markdown like this: # A Header ``` javascript $(document).ready(function() {}) ```
I have a PHP page like this: <? ... Some PHP code here ...
I have a code highlight block for which I would like to have an
I have JavaScript code which copies the value of input file and paste it
I have the JavaScript code to fadein.fadeout the menu, when ever user hovers it.

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.