I am having issue with knockout and jquery dialog. The thing is I am opening the dialog on hyperlink .The issue is every time I close and open the dialog, I am getting the duplication data. The data is being appended again and again whenever I close and open the dialog. I tried destroying the dialog on close of dialog but still the issue persists.

WHAT I AM DOING IN THE FOLLOWING CODE

1) I am opening a div with a dialog .In the open event of the dialog i am getting data from the server .

2) I am using knockout view model to store and persist the data.

WHAT IS THE ISSUE

I am getting the duplicate rows on each hyperlink click whenever i open and close the dialog.The issue will not happen on the first page load.The issue appears only on further clicking of hyperlink.

```
 <div id="divforjobactivity" class="hidden">
    <h5 class="title1" style="padding-left: 500px">
        Job Activity Form</h5>
    <table id="gvActivityForm" class="test">
        <thead>
        <tr> <td> <div id="divstatus"></div> </td></tr>
        <tr>
            <th class="thdata">
             Y1
            </th>
 <th class="thdata">
             Y2
            </th>

            </tr>
        </thead>

        <tbody data-bind="foreach: arraytoadd">

                    <tr>

                         <td data-bind="text: y1"></td>

                        <td data-bind="text: y2"></td>

    </table>

</div>
 $(document).on("click", "[id*=hypJobActivity]", function () {

      var $tr = $(this).closest('tr');  // gets closest parent tr element to the anchor element
      var x1 = $(".x1", $(this).closest("tr")).html()
      var $addJobActivityContainer = $("#divforjobactivity"); 
      TemplateFunction = function () {

        var self = this;
        self.y2 =ko.observable(0);
        self.y1 = ko.observable(0);        
    }
    // set the view model for 
      JobActivity = function () {

        var self = this;
        self.errors = ko.observableArray();
        self.arraytoadd = ko.observableArray();
        self.addevent = function () {

            self.arraytoadd.push(new TemplateFunction());
        }
    }      

    jobactivityVM = new JobActivity();
    ko.cleanNode($addJobActivityContainer[0]);
    ko.applyBindings(jobactivityVM, $addJobActivityContainer[0]);
    obj = {};        
    obj.x1 = x1;       
    $("#divforjobactivity").dialog({ height: 320,width: 1230,modal: true,

 open:function   (event,ui)         
            $.ajax({     //start ajax call for posting and getting the data back
                type: 'POST',
                url: 'PopupWebService.asmx/ReceiveandSendJobActivity',
                data: JSON.stringify({ item: obj }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {                      

                    for (var i = 0; i < response.d.length; i++) {

                        var x = new TemplateFunction();
                        x.y1(response.d[i].Y1); 
                        x.y2=((response.d[i].Y2);                                       
                        jobactivityVM.arraytoadd.push(x);
                    }                  

                }, //end of sucess att

                close: function (event, ui) {

                    $("#divforjobactivity").dialog("destroy");
                    $("#divforjobactivity").remove();
                }, // end of close 

                error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("Unable to retrieve requested information " + errorThrown);

                }     //end of error

            }); //END OF DIALOG

```