I'm trying to make tableView with select-all checkbox on spine.js and coffeescript. I cant understand how i can bind select-all click to select all models in table. "select-all" checkbox is rendered at UserList view. ItemView code:
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')
ItemList code:
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)
Any help would be appreciated! Thanks!
It looks like you're close. In UserList create the select_all_chb function and have it change the users:
class UserList
select_all_chb: =>
User.each (user) ->
user.selected = true
user.save()
Since you've bound the "change" event to "render", all the checklist items will be redrawn.