On Github zzolo / ractive-js-example-presentation
Created by Alan Palazzolo
[ { "Actual": true, "BlockNumber": 1122, "DepartureText": "3 Min", "DepartureTime": "/Date(1377800220000-0500)/", "Description": "Emerson/26Av-Broadway", "Gate": "", "Route": "5", "RouteDirection": "NORTHBOUND", "Terminal": "F", "VehicleHeading": 0, "VehicleLatitude": 44.9888311, "VehicleLongitude": -93.2898608 }, ... ]
<h2>Bus Stop: {{stop}}</h2> <ul> {{# buses:i}} <li>{{Route}}{{Terminal}} in {{DepartureText}}.</li> {{/ buses}} </ul>
var $el = $('.container-output'); var template = $('#template-id');
var ractiveView = new Ractive({ el: $el, template: template, data: { stop: busStop, buses: [ .. ] } });
<h2>Bus Stop: {{stop}}</h2> <ul> {{# buses:i}} <li>{{Route}}{{Terminal}} {{# Actual}} {{ DepartureText.toLowerCase() === 'due' ? 'is Due' : 'arrives in ' + DepartureText }} {{/ Actual}} {{^ Actual}} arrives at {{DepartureText}}{{/ Actual}}. </li> {{/ buses}} </ul>
var ractiveView = new Ractive({ el: $el, template: template, data: { stop: busStop, buses: [] } }); onBusUpdate(function(data) { ractiveView.set('buses', data); });
var buses = { a: 1, b: 2 }; var ractiveView = new Ractive({ el: $el, template: template, data: { stop: busStop, buses: buses } }); buses.c = 4; ractiveView.update('buses');
var buses = []; var count = 0; var ractiveView = new Ractive({ el: $el, template: template, data: { stop: busStop, buses: buses } }); onBusUpdate(function(data) { buses.push(data[count++]); });