// /hotels/:id
function run ( id ) {
var Hotel = Backbone.Model.extend( { urlRoot : "/hotels" } );
var hotel = new Hotel( { id: id } );
hotel.on( "change", function ( hotel ) {
$el.html(
Templates[ "hotel" ]( hotel ) );
});
hotel.fetch();
}
// /hotels/:id
function run ( id ) {
var Hotel = Backbone.Model.extend( { urlRoot : "/hotels" } );
var hotel = new Hotel( { id: id } );
hotel.on( "change", function ( hotel ) {
$el.html(
Templates[ "hotel" ]( hotel ) );
});
hotel.fetch();
}
server.get( "/hotels/:id", ( req ) => run( req.params.id ) );
<script>
console.log( "asdf" );
</script>
<div>
console.log( "asdf" );
</div>
backbonesync
Backbone.sync = function ( method, model ) {
if ( method == "read" ) {
request( model.url(), /* ... */ );
}
/* ... */
};
app
function run ( id, Backbone, $el, Templates ) {
var Hotel = Backbone.Model.extend( { urlRoot : "/hotels" } );
var hotel = new Hotel( { id: id } );
hotel.on( "change", function ( hotel ) {
$el.html(
Templates[ "hotel" ]( hotel ) );
});
hotel.fetch();
}
app
function run ( id, Backbone, $el, Templates, done ) {
var Hotel = Backbone.Model.extend( { urlRoot : "/hotels" } );
var hotel = new Hotel( { id: id } );
hotel.on( "change", function ( hotel ) {
$el.html(
Templates[ "hotel" ]( hotel ) );
done();
}
hotel.fetch();
}
server
var Backbone = require( "backbone" );
var $ = require( "tready-dom" );
var Handlebars = require( "handlebars" );
var Templates = { "hotel": Handlebars.template( require( "./hotel.html" ) ) };
server.get( "/hotels/:id",
function ( req, res, next ) {
req.mnug.$el = $( "div" );
run( req.params.id, Backbone, req.mnug.$el, Templates, next ) );
}, function ( req, res ) {
res.send( req.mnug.$el.html() );
}
);
server.listen( 80 );