小さなプロジェクトを作ろうとして、バックボーンjsを学んでいます。
of te ページで、require.js と text.js を cloudflare CDN からロードします。
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.8/require.min.js">//</script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/require-text/2.0.10/text.js">//</script>
「ボックス」と呼ばれるバックボーン ビューを作成しました。
var Boxes = Backbone.View.extend({
// Choose an element.
el : '.content',
render : function () {
// Captur "this" -> the backbone view itself.
var that = this;
$(this.el).html('how do I load a html template here?');
}
});
問題:
ページに text.js プラグインを追加すると、次のエラーが発生します。
無名の define() モジュールの不一致: function (module) { 'use strict'; ……
したがって、require.js と text.js の両方をロードすることはできません。他のスクリプトがない空白のページでも上記のエラーが発生します。
- require js をテキスト js で動作させた後、そのビューの HTML テンプレートをロードするにはどうすればよいですか?
現在、index.html ページでテンプレートをインラインで記述する方法を知っています。
私はこのようにします:
var Boxes = Backbone.View.extend({
el : '.content',
render : function () {
var that = this; // This backbone view
var template = _.template($('#user-list-template').html(), {});
that.$el.html(template);
}
});
ありがとうございました!