1

as I've been discovering this library more and more, I'm stuck at this one single thing.

I have this staticData array:

staticData = {
    buildingsQueue : [
        { current: false, building : 14, queueID : 1, elapsed : 27, finish : 46 },
        { current: false, building : 4, queueID : 2, elapsed : 0, finish : 25 }
    ]
}

And this Ractive instance:

var townController = {
    init : function () {
        townTPL = new Ractive({
            el : 'pageContainer',
            append : true,
            template : templates.town,
            data : {
                staticUrl : staticData.url,
                queue : staticData.village.buildingsQueue
            }
        });

        townTPL.observe('queue.*',function(newValue,oldValue,keypath){
            console.log('changed::'+keypath);
        });

    }

My buildingsQueue will get processed one at a time, and the townController will set the current key to true so I decided to make an observer for queue.* following Rich's example

var ractive = new Ractive({
  el: myContainer,
  template: myTemplate,
  data: {
    people: [
      {name: 'Rich Harris'},
      {name: 'Marty Nelson'}
    ]
  }
});

ractive.observe('people.*', function(newValue, oldValue, keypath) {

});

var people = ractive.get('people');
people.push({name: 'Jason Brown'});
//newValue will equal 3, and the keypath will be people.length

The problem is that buildingQueue changes over time, and pushing data like the following doesn't fire the observer callback:

var list = TownTPL.get('queue');
list.push({ current: true, building : 1, queueID : 4, elapsed : 0, finish : 36 })
// OR   
staticData.buildingsQueue.push({ current: true, building : 1, queueID : 4, elapsed : 0, finish : 36 });

The observer doesn't fire as Rich's documentation says it should in it's example. My logic is that observers only work with the array items that are in the array when initiated, but I'm pretty sure that's not true and it should work with dynamic arrays, so, please enlighten me on this one.

TO BE AWARE OF I'm firing the push events from outside the init function , Javascript Console for example, or another javascript object.

FIXED PROLEM I've updated the plugin to the edge version, still 0.4.0 like the one I was using, but, this one was released two days ago. Thanks Rich and Marty, whatever you did in those commits.

4

1 回答 1

0

Fixed by updating to the edge version.

于 2014-05-20T23:33:28.150 回答