我的模型有问题。当我去保存状态时,我得到
未捕获的类型错误:无法调用未定义的方法“get”
有人有想法么?我是 Backbone 的超级新手,甚至是 Coffeescript 的新手。
View = require 'views/base/view'
module.exports= class TaskView extends View
autoRender: true
eventSounder:false
taskRemoveTimeout:500
completeTask:(e)=>
e.preventDefault() if e
e.stopPropagation() if e
@toggleStatus()
@model.save {
status: @model.get('status') # error
}, {
success: =>
unless @removeTaskTimeout
@removeTaskTimeout = setTimeout(@removeTaskItem, @taskRemoveTimeout)
}
toggleStatus: =>
if @model.get('status') is 'OPEN'
if @removeTaskTimeout
clearTimeout @removeTaskTimeout
@removeTaskTimeout = null
@model.set('status', 'CLOSED')
else if @model.get('status') is 'CLOSED'
@model.set('status', 'OPEN')
removeTaskItem: =>
if @model.get('status') is 'CLOSED'
@eventSounder = true
@datastore.userTasks.remove @model
@model?.collection?.remove @model
console.log @model
getTemplateData: =>
td = super
td.completeClass = "complete" if @model.isComplete?()
td.assignedBy = @datastore.dimensionUsers.getUserName(@model.get('assigner'))
if !td.assignedBy
td.assignedBy = "Dimension User Not Found"
td
更新:
这是调用 completeTask 的事件的视图:
View = require 'views/base/task'
template = require 'views/templates/fanview/right/task_carousel_item'
module.exports = class TaskCarouselItem extends View
template: template
template = null
className: 'item'
listen:
'change model' : 'render'
'toggleStatus model' : 'completeTask'
attach: ->
super
id = @model.id
@$el.data('id', id)
@publishEvent 'taskCarousel:status:update'
initialize: ->
super
console.log 'Initialize', @model