Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Backbone.js 下划线嵌套的带有主干视图的每个循环_Backbone.js_Requirejs_Underscore.js - Fatal编程技术网

Backbone.js 下划线嵌套的带有主干视图的每个循环

Backbone.js 下划线嵌套的带有主干视图的每个循环,backbone.js,requirejs,underscore.js,Backbone.js,Requirejs,Underscore.js,尝试将每个measureView及其子视图的渲染嵌套在同一measureView.js文件中。我们将require.js用于路径定义,因此请原谅一些未定义的var名称。问题出在measuresView.js中,在嵌套的3;每个方法中,因为新的BeatView返回uncaughtTypeError:undefined不是一个函数。我们尝试从第一个33;[2]函数外部手动调用新BeatView,以确保它不在require.js BeatView变量的作用域内,但使用此函数时出现了相同的错误:新Bea

尝试将每个measureView及其子视图的渲染嵌套在同一measureView.js文件中。我们将require.js用于路径定义,因此请原谅一些未定义的var名称。问题出在measuresView.js中,在嵌套的3;每个方法中,因为新的BeatView返回uncaughtTypeError:undefined不是一个函数。我们尝试从第一个33;[2]函数外部手动调用新BeatView,以确保它不在require.js BeatView变量的作用域内,但使用此函数时出现了相同的错误:新BeatView{model:this.component.models[0]。获取'beats'。models[0],el:this.el}; . 使用嵌套的eachs和作用域有什么特别的地方吗?或者我遗漏了什么

measuresView.js:

beatView.js:

其他信息:

主干结构:

Component (basically an instrument)
  ↳ A collection of Measure(s)
    ↳ Measure
      ↳ A collection of Beat(s)
        ↳ Beat
节拍模式:

//filename: models/beat.js
/*
  This is the beat model.
  It only knows about whether or not it
  is selected.
*/
define([
  'underscore',
  'backbone'
], function(_, Backbone) {
  var beatModel = Backbone.Model.extend({
    defaults: {
      selected: false,
      state: 'OFF'
    },
    initialize: function(){
    },
    getStyleClass: function() {
      if (this.selected) {
        return 'ON';
      }
      else {
        return 'OFF';
      }
    }
  });
  return beatModel;
});
节拍系列:

//Filename: collections/beats.js
/*
  This is the beats collection.
  It is a collection of beat models.
*/
define([
  'jquery',
  'underscore',
  'backbone',
  'backbone/models/beat'
], function($, _, Backbone, beatModel){
  return Backbone.Collection.extend({
    model: beatModel,
    initialize: function(){
    }
  });
  //return new beatsCollection();
});
测量模型:

//filename: models/measure.js
/*
  This is the measure model.
  A component has a collection of these models.
  these models have a collection of beats.
*/
define([
  'underscore',
  'backbone',
  'backbone/collections/beats'
], function(_, Backbone, beatsCollection) {
  var measureModel = Backbone.Model.extend({
    defaults: {
      label: '0/4',
      beats: beatsCollection,
      numberOfBeats: 0,
      divisions: 8
    },
    initialize: function(){     
    }
  });
  return measureModel;
});
措施收集:

//filename collections/measures.js
/*
  This is the measures collection.
  It is a collection of measure models.
*/
define([
  'jquery',
  'underscore',
  'backbone',
  'backbone/models/measure'
], function($, _, Backbone, measureModel){
  return Backbone.Collection.extend({
    model: measureModel,
    initialize: function(){
    }
  });
});
内部错误:

Uncaught TypeError: undefined is not a function measuresView.js:100
(anonymous function) measuresView.js:100
_.each._.forEach underscore.js:78
(anonymous function) measuresView.js:96
_.each._.forEach underscore.js:78
Backbone.View.extend.render measuresView.js:88
Backbone.View.extend.initialize measuresView.js:72
Backbone.View backbone.js:1236
child backbone.js:1467
Backbone.View.extend.render componentView.js:63
Backbone.View.extend.initialize componentView.js:54
Backbone.View backbone.js:1236
child backbone.js:1467
(anonymous function) componentsView.js:201
_.each._.forEach underscore.js:78
Backbone.View.extend.render componentsView.js:192
Backbone.Router.extend.newSong router.js:42
(anonymous function) backbone.js:967
(anonymous function) backbone.js:1164
_.some._.any underscore.js:207
_.extend.loadUrl backbone.js:1162
_.extend.start backbone.js:1128
initialize router.js:157
initialize SOF.js:15
....
Uncaught TypeError: undefined is not a function measuresView.js:86
Backbone.View.extend.render measuresView.js:86
Backbone.View.extend.initialize measuresView.js:72
Backbone.View backbone.js:1236
child backbone.js:1467
Backbone.View.extend.render componentView.js:63
Backbone.View.extend.initialize componentView.js:54
Backbone.View backbone.js:1236
child backbone.js:1467
(anonymous function) componentsView.js:201
_.each._.forEach underscore.js:78
Backbone.View.extend.render componentsView.js:192
Backbone.Router.extend.newSong router.js:42
(anonymous function) backbone.js:967
(anonymous function) backbone.js:1164
_.some._.any underscore.js:207
_.extend.loadUrl backbone.js:1162
_.extend.start backbone.js:1128
initialize router.js:157
initialize SOF.js:15
....
外部错误:

Uncaught TypeError: undefined is not a function measuresView.js:100
(anonymous function) measuresView.js:100
_.each._.forEach underscore.js:78
(anonymous function) measuresView.js:96
_.each._.forEach underscore.js:78
Backbone.View.extend.render measuresView.js:88
Backbone.View.extend.initialize measuresView.js:72
Backbone.View backbone.js:1236
child backbone.js:1467
Backbone.View.extend.render componentView.js:63
Backbone.View.extend.initialize componentView.js:54
Backbone.View backbone.js:1236
child backbone.js:1467
(anonymous function) componentsView.js:201
_.each._.forEach underscore.js:78
Backbone.View.extend.render componentsView.js:192
Backbone.Router.extend.newSong router.js:42
(anonymous function) backbone.js:967
(anonymous function) backbone.js:1164
_.some._.any underscore.js:207
_.extend.loadUrl backbone.js:1162
_.extend.start backbone.js:1128
initialize router.js:157
initialize SOF.js:15
....
Uncaught TypeError: undefined is not a function measuresView.js:86
Backbone.View.extend.render measuresView.js:86
Backbone.View.extend.initialize measuresView.js:72
Backbone.View backbone.js:1236
child backbone.js:1467
Backbone.View.extend.render componentView.js:63
Backbone.View.extend.initialize componentView.js:54
Backbone.View backbone.js:1236
child backbone.js:1467
(anonymous function) componentsView.js:201
_.each._.forEach underscore.js:78
Backbone.View.extend.render componentsView.js:192
Backbone.Router.extend.newSong router.js:42
(anonymous function) backbone.js:967
(anonymous function) backbone.js:1164
_.some._.any underscore.js:207
_.extend.loadUrl backbone.js:1162
_.extend.start backbone.js:1128
initialize router.js:157
initialize SOF.js:15
....

所以当你在循环之外尝试新的BeatView时,你也会遇到同样的错误?是的。它没有访问权限是没有意义的,因为它也在require posted now errors posted中,所以问题是BeatView没有定义。如果您有循环依赖项,可能会在requirejs中发生这种情况,并且模块中可能存在脚本错误。BeatView是否在其依赖项列表中包含MeasureView模块?因为它一直困扰着我,我没有发现您提供的代码有任何错误,我已经运行了一些测试,我不知道require如何对不同的错误做出反应。有了这个未定义的错误,唯一有意义的是beatView文件实际上没有返回类。如果您返回函数以外的任何内容,您将得到一个未定义的函数。但是你发布的代码应该没有错误。在返回beatView文件之前,您是否可以尝试在beatView文件中创建一个beatView,以验证您是否真的具有功能?
Uncaught TypeError: undefined is not a function measuresView.js:86
Backbone.View.extend.render measuresView.js:86
Backbone.View.extend.initialize measuresView.js:72
Backbone.View backbone.js:1236
child backbone.js:1467
Backbone.View.extend.render componentView.js:63
Backbone.View.extend.initialize componentView.js:54
Backbone.View backbone.js:1236
child backbone.js:1467
(anonymous function) componentsView.js:201
_.each._.forEach underscore.js:78
Backbone.View.extend.render componentsView.js:192
Backbone.Router.extend.newSong router.js:42
(anonymous function) backbone.js:967
(anonymous function) backbone.js:1164
_.some._.any underscore.js:207
_.extend.loadUrl backbone.js:1162
_.extend.start backbone.js:1128
initialize router.js:157
initialize SOF.js:15
....