【发布时间】:2013-12-12 05:29:53
【问题描述】:
.: 编辑 :. 如果您遇到同样的问题,请检查您的变量初始化,我忘记了 new。
我不断收到 TypeError: this._ensureElement is not a function 并且更早收到 TypeError: this._reset is not a function 但我无法真正重新创建后者的确切设置。
我的脚本顺序正确:
<script src="js/components/jquery.js"></script>
<script src="js/components/underscore.js"></script>
<script src="js/components/backbone.js"></script>
<script src="js/script.js"></script>
我的模型在我的收藏之前注册。
这是一个购物车应用程序。
#namespacing
App =
Collection : {}
Model : {}
View : {}
###
MODEL
###
class ModelItem extends Backbone.Model
#default values
defaults:
name : 'Product Name'
quantity : 0
unit : 'kg'
#Increase or decrease the quantity
change_quantity : (type) ->
qty = @get 'quantity'
@set 'quantity', if type is 'increase' then ++qty else --qty
###
COLLECTION
###
class CollectionItems extends Backbone.Collection
model: ModelItem
###
VIEW
###
class ViewItems extends Backbone.View
window.view = ViewItems()
window.item = ModelItem()
【问题讨论】:
-
错误在哪一行?
标签: javascript backbone.js coffeescript