Backbone Collections未定义

时间:2015-08-19 21:59:57

标签: backbone.js collections

在我的数据库中,我只是试图从我的“countries”数组中获取每个对象,但是当我运行它时,控制台告诉我我的集合未定义。

index.js

  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;

0 个答案:

没有答案