是否可以在同一个 Spine.js 中有两个 Controller :Apartments 和 Map。有没有办法在选择公寓时调用让 map 做某事?
# Apartments
class Show extends Spine.Controller
events:
'click [data-type=edit]': 'edit'
'click [data-type=back]': 'back'
constructor: ->
super
@active (params) ->
@change(params.id)
change: (id) ->
@item = Apartment.find(id)
@render()
render: ->
@html @view('apartments/show')(@item)
# also update the map here.
最佳答案
我猜你没有什么选择
使用路由
使用 Spine 的路由导航到公寓 url 并更新 map 。您可以在 Spine 的 Contacts example 上查看示例.
在你的 index.coffee 上定义/apartment 路由:
@routes '/apartment/:id': (params) -> @apartmentList.active(params) @map.show.active(params)
在你的侧边栏/公寓列表 Controller 上使用@navigate 来改变状态
change: (item) => @navigate '/apartment', apartment.id
最后在您的 map Controller (like here) 上捕获事件事件并更新 map
使用事件
选择公寓火灾事件时
Spine.trigger 'selectApartment', item.id然后在 map Controller 上捕获此事件:
Spine.bind 'selectApartment', onSelectAparmtnet
关于javascript - Spine.js 中的 Controller 间通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13140026/