Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I am getting data first time while assiging list<string> values into observable array in knockout.js.BUt second time data is not refreshing.previous data is loading.
C#
self.jobHistory = ko.observableArray([]);
        self.history = ko.observable("");


PHP
$.getJSON("/api/helpdeskapi/JobHistory/" + ticketEntity.JobId, function (data) {
           if (data.length > 0) {
               $.each(data, function (key, val) {
                   self.history ( val);
                   self.jobHistory.push(self.history());
               });
           }
       });



XML
<table style= "width:250px; " cellpadding="0" cellspacing="0" data-bind="foreach:jobHistory">
                       <tbody>

                           <tr></tr>
                           <tr>
                           <td align="left" valign="top" data-bind="text:$data">
                          </td>
                          </tr>
                       </tbody>
                     </table>



please give me a solution to solve the problem.
Posted
Updated 20-Aug-13 1:13am
v3
Comments
ZurdoDev 20-Aug-13 7:21am    
What is first time and what is second time. Give some details so we can help.
josh-jw 20-Aug-13 7:41am    
in table more than one record is there. each record have history . when i click on any item i am able to get the item and show the history. but clicked on second record ,not getting updated
hisoty means history of second record.when i put break point checked in my javascript file.i can see updated value in my observable array. but that updated data is not loading in html.i dnt know if there any issue in using $ data for binding
josh-jw 20-Aug-13 8:40am    
var self = this;
Ashutosh Mahto 20-Aug-13 7:57am    
What is self? May be there is binding issue with the ViewModel. Otherwise it should work if you are just using ko.applyBindings(self);
josh-jw 20-Aug-13 8:40am    
var self = this;

Refer to this Knockout foreach-binding[^]
 
Share this answer
 
i fixed it. i for got to clear the value in obervable array and add below code.

HTML
self.jobHistory([]);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900