我正在尝试在spine.js 和coffeescript 上使用全选复选框制作tableView。我无法理解如何绑定全选单击以选择表中的所有模型。“全选”复选框在 UserList 视图中呈现。项目查看代码:
class UserItem extends Spine.Controller
className: 'user-item'
tag: 'tr'
elements:
'input[type="checkbox"]': 'checkbox'
events:
'click input[type="checkbox"]': 'itemChbClicked'
constructor: ->
super
@item.bind("update", @render)
@item.bind("destroy", @remove)
render: ->
@html require('views/user/item')(@item)
@
remove: =>
@el.remove()
itemChbClicked: (e) ->
@item.selected = @checkbox.is(':checked')
物品清单代码:
class UserList extends Spine.Controller
className: 'user-list'
elements:
'.items': 'items'
".select-all": "select_all_chb"
constructor: ->
super
@html require('views/user/list')()
User.bind("create", @addOne)
User.bind("refresh", @addAll)
User.fetch()
addOne: (user) =>
view = new UserItem(item: user)
@items.append(view.render().el)
addAll: =>
User.each(@addOne)
任何帮助,将不胜感激!谢谢!