在我的数据库中,我只是试图从我的“countries”数组中获取每个对象,但是当我运行它时,控制台告诉我我的集合未定义。
var Backbone = require('backbone')
var App = require('./app.js')
var countryCollection = require('./collections/countries');
var countryModel = require('./models/country')
var countryView = require('./views/country-bio');
App.Views.CountryBio = new CountryBioView;
App.Router = Backbone.Router.extend({
routes: {
'bio.html(/)': 'index',
'*actions': 'defaultRoute'
},
index: function() {
console.log(countryCollection)
console.log('this works')
},
defaultRoute: function() {
console.log("404 Page Not Found")
}
})
App.Router = new App.Router;
Backbone.history.start();
var Backbone = require('backbone');
var App = require('../app');
var Country = require('../models/country');**strong text**
var CountryCollection = Backbone.Collection.extend({
url: 'http://localhost:3000/countries',
model: Country
});
App.Collections.country = new CountryCollection;
module.exports = App.Collections.country;
var Backbone = require('backbone');
var App = require('../app');
App.Models.Country = Backbone.Model.extend({
url: function() {
return 'http://localhost:3000/countries';
}
});
module.exports = App.Models.Country;
var $ = require('jquery');
var Backbone = require('backbone');
var countryBioTemplate = require('../templates/countryBio.hbs');
var App = require('../app');
var CountryBio = Backbone.View.extend({
el: $('main'),
collection: App.Collections.country,
render: function () {
var _this = this;
var countryCollection = this.collection;
console.log(countryCollection)
// Fetch Collection from Server
// countryCollection.fetch().done(function (country) {
// _this.$el.html(countryBioTemplate(country));
// });
}
});
module.exports = CountryBio;