In show.ejs:
<%= JSON.stringify(this) %> results in {}
<%= JSON.stringify(info) %> error message "ReferenceError: info is not defined"
Controller:
steal('can','./init.ejs','./show.ejs', 'birds/models/hotspot.js', 'birds/models/bird.js','../../lib/moment','can/view/modifiers', function(can, initEJS,showEJS, Hotspot, Bird){
/**
* @class birds/controls/hotspots
* @alias Hotspots
*/
return can.Control(
/** @Static */
{
defaults : {
}
},
/** @Prototype */
{
init : function(){
console.log('no way')
this.list = new Hotspot.List();
this.element.html(initEJS(this.list));
},
index : function(){
console.log('ok list')
this.localHotspots(this);
},
show : function(locID){
this.element.html(showEJS,Hotspot.findOne({id: locID, fmt: 'json'}))
var that = this;
Hotspot.findOne({id: locID, fmt: 'json'},function(hotspot){
that.element.html(showEJS, hotspot);
console.log(hotspot)
});
},
findHostspots: function (params) {
console.log(params)
return Hotspot.findAll(params)
},
localHotspots: function(control){
navigator.geolocation.getCurrentPosition(
function(position) {
console.log(position.coords.longitude)
birds = control.findHostspots({'lng':position.coords.longitude,'lat':position.coords.latitude,'fmt':'json'})
control.list.replace(birds);
},
function() {
alert('Error getting location');
}
);
},
'#local click': function (el) {
console.log('clicked locate')
this.localHotspots(this);
},
'.hotspot click': function (el) {
console.log('hot spot clicked: ' + el.attr('id'))
this.show(el.attr('id'));
}
});
});
show.ejs
<div id="hotspot">
<div id="header">
Hola!
</div>
<%= JSON.stringify(info) %>
</div>