gpt4 book ai didi

javascript - 卓别林在获取后如何渲染模型? View 如何知道获取已完成?

转载 作者:行者123 更新时间:2023-12-02 19:21:00 24 4
gpt4 key购买 nike

我正在做一个基于 Chaplin-boilerplate 的示例项目,并且工作完美,但我无法理解在获取完成后 View 如何渲染,例如,您可以在事件更改时使用 Backbone,或者使用fetch 方法中的回调,但是使用 chaplinjs 如何执行此操作?是否使用 Backbone 的事件更改? Chaplinjs 的哪个类绑定(bind)了事件?绑定(bind)进展如何?

class CampaignController extends Chaplin.Controller

title: 'Campaign'
index: (params) ->
campaign = new Campaign()
@view = new CartView model: campaign


class CartView extends View
template: template
template = null
container: '#cart'
autoRender: true
className: 'cart'
initialize: ->
super
render: ->
super

class Campaign extends Model

initialize: (attributes, options) ->
super
@urlRoot = "http://localhost/store/js/test-data/cart.json"
@fetch()

最佳答案

在执行@view = new CartView model: marketing时,您将campaign对象作为模型分配给 View 。ChaplinJS View 类自动执行以下操作:

if (target === 'model' || target === 'collection') {
prop = this[target];
if (prop) {
this.listenTo(prop, eventName, callback);
}
}

这应该可以回答你的问题

关于javascript - 卓别林在获取后如何渲染模型? View 如何知道获取已完成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12533075/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com