2

there is an object in my application , lets call it myObject , so myObject has some keys , and is being rendered in my html using jsblocks library.

Due to lack of full documentation , I still can't figure out how to update my view upon updating this object from server side , for example :

function fetchArtists()
{
     // load data
        $.post( "../db/fetch/", { table: "artists"})
          .done(function( data ) {
            artists=JSON.parse(data);            
            //console.log( JSON.parse(data)  );
          });
}

this is a function that fetches object data from server and stores it in object artists.

and this is where i upgrade my view :

blocks.query(artists,$(".artist-list,.artist-data"));

I want to be able to use blocks.observable(artists); to upgrade view upon calling a new fetch , but it is not working , anyone knows the correct way to do this ?

ProllyGeek
  • 15,517
  • 9
  • 53
  • 72

1 Answers1

3

You are on the right path when saying you should update the data with blocks.observable. The way you should do it should be something similar to the code below:

var Model = {
  artists: blocks.observable([])
};

function fetchArtists()
{
    // load data
    $.post( "../db/fetch/", { table: "artists"})
       .done(function( data ) {
           Model.artists.reset(JSON.parse(data));
       });
}

blocks.query(Model);
astoilkov
  • 556
  • 1
  • 5
  • 14