我正在尝试为这个“游戏视图”在我的木偶视图中添加一个无尽的滚动我确信我的逻辑在正确的轨道上,但我被告知我可能需要直接在 jQuery 中修改一些东西或类似的愚蠢的东西,因为在复合视图中使用“无限滚动”..它们可能有些怪癖。
这是一些代码。
getGames: (url, params = {}) ->
_.defaults params,
oauth_token: msgBus.reqres.request "get:current:token"
#country: "us"
games = new GamesCollection
games.url = "https://api.twitch.tv/kraken/#{url}?callback=?"
games.fetch
reset: if params.offset is 0 then true else false
data: params
games
msgBus.reqres.setHandler "games:top:entities", ->
API.getGames "games/top",
limit: 25
offset: 0
Msgbus 调用。
msgBus.reqres.setHandler "games:scroll", (page) ->
API.getGames "games/top",
limit: 25
offset: page
msgBus.reqres.setHandler "games:top:entities", ->
API.getGames "games/top",
limit: 25
offset: 0
游戏控制器
gameRegion: (collection) ->
view = @getGameView collection
@listenTo view, "childview:game:item:clicked", (child, args) -> # listen to events from itemview (we've overridden the eventnamePrefix to childview)
console.log "game:item:clicked" , args.model
Backbone.history.navigate "games/streaming/#{args.model.get("game").name}", trigger:false
msgBus.commands.execute "app:stream:list", @layout.streamRegion, args.model
@listenTo view, "games:fetchmore", (page) ->
#console.log "game:item:clicked" , args.model
msgBus.reqres.request "games:scroll", page
最后,游戏视图
define ['apps/games/list/templates', 'views/_base', 'msgbus'], (Templates, AppView, msgBus) ->
class GameItem extends AppView.ItemView
template: _.template(Templates.gameitem)
tagName: "li"
className: "col-lg-3 col-md-4 col-sm-6 col-xs-12"
triggers:
"click" : "game:item:clicked"
TopGameList: class TopGameList extends AppView.CompositeView
template: _.template(Templates.topgame)
itemView: GameItem
itemViewContainer: "#gameitems"
events:
'scroll': 'checkScroll'
checkScroll: (e) ->
console.log "scroll", e
triggerPoint = 100 #100px from the bottom
if @el.scrollTop + @el.clientHeight + triggerPoint > @el.scrollHeight
console.log "trigger:scroll"
@collection.offset += 1 #Load next page
msgBus.events.trigger "games:fetchmore", @collection.offset
如果您对我正在使用的 API 感到好奇,这里是 github 的链接...
谢谢大家,很抱歉发了这么长的帖子。干杯。