I’ve just started using spine and I’m having trouble understanding a few things…
class Spk.Register extends Spine.Controller
render: ->
@html("<h1>Registration!</h1>")
…
Zepto(function($) {
new Spk.Register({
el: $("#data")
});
});
…I was expecting this to replace any html in the #data element with the html passed to @html when the controller is instantiated, but it doesn’t, nothing happens at all.
I’ve also tried putting the render method in the constructor function but again nothing happens.
How would I replace the html in body with given html when the controller is instantiated?
The problem is the
render()method isn’t called.You have to call it explicitly after controller instantiated.
Anyway, I think you shouldn’t do any rendering in the constructor.
Better option is:
after the data loaded from the server,
EDIT
Just very simple code snippet how it could be (CoffeeScript, using jQuery):
The
Taskmodel class:The controller:
The initialization code (another possibility could be Spine.js controller stack):
Note that it requires also
route.js(included in Spine.js) and I’ve used Transparency template engine (it’s@el.render()meth). Then the template looks like: