Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The best way to solve your problem is to use a binding library such as knockout. With it you separete your data and your view and only have to worry how you update the data, the view will get updated automatically. This is what it seems you are currently struggeling with.</p> <p>That's why I made small sample generating a list and updating the data by constantly polling to it (using a fake service which always returns the same data which changes randomly).</p> <p>Here is the example I did by using knockout: Please take a look at the knockout documention page: <a href="http://knockoutjs.com/documentation/introduction.html" rel="nofollow">http://knockoutjs.com/documentation/introduction.html</a></p> <p>HTML: Define a simple table with header and content</p> <pre><code>&lt;table style="width: 100%" border="1"&gt; &lt;thead&gt; &lt;tr&gt; &lt;td&gt; &lt;p&gt;&lt;b&gt;Classes&lt;/b&gt; &lt;/p&gt; &lt;/td&gt;http://jsfiddle.net/yBat5/#fork &lt;td&gt; &lt;p&gt;&lt;b&gt;Childs&lt;/b&gt; &lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody data-bind="foreach: Classes"&gt; &lt;tr&gt; &lt;td&gt; &lt;p data-bind=" text: Class"&gt;&lt;/p&gt; &lt;/td&gt; &lt;td&gt; &lt;p data-bind=" text: Child"&gt;&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p>JavaScript:</p> <pre><code>$(function () { // define a ViewModel for your data function ViewModel() { this.Classes = ko.observableArray([{ "Class": "test", "Child": "Max" }, { "Class": "test2", "Child": "Walter" }]); } var vm = new ViewModel(), dummyData = []; // create a lot of dummy data sets for (var i = 0; i &lt; 1000; i++) { dummyData.push({ "Class": "test " + i, "Child": "Child" + i }) } // constantly poll for new data // JS fiddle implements a simple echo service, which we can use // to simulate data changes we change a rendon number function poll() { $.ajax({ "url": "\/echo\/json\/", "type": "POST", "data": { "json": JSON.stringify(dummyData), "deley": 3 }, "success": function (data) { vm.Classes(data); // poll again (3 seconds so we see how fast the update is) setTimeout(poll, 300); // change a random entry to see that data changes var randomnumber=Math.floor(Math.random()*1000); dummyData[randomnumber].Child = "Child" +randomnumber +" changed" } }); } poll(); // apply it to the page, knocout now does the binding for you ko.applyBindings(vm); }); </code></pre> <p>Fiddle: <a href="http://jsfiddle.net/yBat5/3/" rel="nofollow">http://jsfiddle.net/yBat5/3/</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload