Esto realmente me confunde, creo que soy estúpido pero he buscado y he hecho lo que pude. Cada vez que declaro una vista y ejecuto la prueba BDD con jazmín, siempre devuelve "indefinido no es una función". Este es el códigobackbone view - no está definido
window.LocationView = Backbone.View.extend({
initialize: function() {
// create new marker first
this.marker = new google.maps.Marker({
title: this.model.get('name'),
draggable: true,
animation: google.maps.Animation.DROP,
position: new google.maps.LatLng(this.model.get('lat'), this.model.get('long')), // give the position here
});
// bind events
this.model.bind('change', this.render, this);
},
render: function() {
this.marker.setTitle(this.model.get("name"));
this.marker.setPosition(new google.maps.LatLng(this.model.get('lat'), this.model.get('long')));
},
});
Así es como lo declaré:
this.view = new LocationView({model: this.location});
this.view = new LocationView();
// neither of these ones work.
Este es el error al ejecutar el código con el jazmín:
TypeError: undefined is not a function
at [object Object].make (http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.5.3/backbone-min.js:29:37)
at [object Object]._ensureElement (http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.5.3/backbone-min.js:30:270)
at [object Object].<anonymous> (http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.5.3/backbone-min.js:28:127)
at new <anonymous> (http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.5.3/backbone-min.js:32:136)
at [object Object].<anonymous> (http://localhost/gmap_api/public/test/spec/specs.js:62:21)
at [object Object].execute (http://localhost/gmap_api/public/test/spec/jasmine/jasmine.js:1001:15)
at [object Object].next_ (http://localhost/gmap_api/public/test/spec/jasmine/jasmine.js:1790:31)
at [object Object].start (http://localhost/gmap_api/public/test/spec/jasmine/jasmine.js:1743:8)
at [object Object].execute (http://localhost/gmap_api/public/test/spec/jasmine/jasmine.js:2070:14)
at [object Object].next_ (http://localhost/gmap_api/public/test/spec/jasmine/jasmine.js:1790:31)
No estoy seguro de qué significa "declarar una vista y luego declarar una nueva vista". ¿Estás instanciando un LocationView y luego un segundo LocationView? El primero está bien pero el segundo no? ¿O 'nueva LocationView ({model: this.location}) 'funciona pero' nueva LocationView(); 'no? –
@muistooshort: Lo siento por el mal inglés, lo soluciono. Significa que me indica que LocationView no está definido todo el tiempo, aunque lo haya declarado ?? – nXqd