我有一个非常简单的骨干应用程序,它返回:
undefined is not a function
在控制台中。一切似乎都得到了恰当的定义。知道问题是什么吗?
JS:
$(function () {
var myModel = Backbone.Model.extend({});
var myCollection = Backbone.Collection.extend({
doStuff: function () {
alert("doing Stuff");
},
doOtherStuff: function () {
alert("doing other stuff");
}
});
var myCollectionView = Backbone.View.extend({
template: "<button id='trigger'>Trigger</button>",
initialize: function () {
this.listenTo(this.collection, 'sync', this.collection.doStuff);
this.listenTo(this.collection, 'sync', this.collection.doOtherStuff);
this.render();
},
events: {
"click #trigger": "trigger"
},
render: function () {
$("#app").html(this.template);
},
trigger: function () {
alert("triggering");
$(this).trigger("sync");
}
});
var mymodel = new myModel({});
var mycollection = new myCollection({
model: mymodel
});
var mycollectionview = new myCollectionView({
collection: mycollection
});
});
在小提琴中复制:http://jsfiddle.net/5C238/1/
答案 0 :(得分:1)
你的订单错误
<script src="//jashkenas.github.io/underscore/underscore-min.js"></script>
<script src="//code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="//jashkenas.github.io/backbone/backbone-min.js"></script>