2

Backbone と Require JS の両方が初めてです。

次のエラーが表示されます。

未定義のプロパティ ビューを読み取れません。

したがって、バックボーンは利用できませんが、どこに問題があるのか​​ わかりません。どんな助けでも大歓迎です。

次の3つのファイルがあります。

index.html:

<!DOCTYPE html>
<html lang="en">
  <head>
    <script data-main="boot" src="../libs/require/require.js"></script>
  </head>
  <body>
    <div id="main">Magic!</div>
  </body>
</html>

boot.js:

require.config({
  baseUrl: "../",
  paths: {
      jquery : "libs/jquery/jquery-1.8.3.min",
      underscore : "libs/underscore/underscore-min",
      backbone : "libs/backbone/backbone-min"
  }
});

require( [ "app/views/app" ], function(AppView) {
  var app = new AppView();
});

app.js:

define([
    "jquery",
    "underscore",
    "backbone"
    ], function( $, _, Backbone ) {

    var AppView = Backbone.View.extend({
        el: $( "#main" ),
        initialize: function () {
             this.render();
        },
        render: function() {
            this.el.html("huzzah!");
        }
    });
    return AppView;

});
4

1 に答える 1

3

requirejs で動作させるには、バックボーンをシムする必要があります。

RequireJS ドキュメントから:

requirejs.config({
    shim: {
        'backbone': {
            //These script dependencies should be loaded before loading
            //backbone.js
            deps: ['underscore', 'jquery'],
            //Once loaded, use the global 'Backbone' as the
            //module value.
            exports: 'Backbone'
        }
    }
});
于 2012-12-27T00:27:10.717 に答える