• backbone collection add 事件回调参数


    this.listenTo(this.collection, 'add', this.renderBook);
    
    renderBook: function (item) {
            var bookView = new app.BookView({
                model: item
            });
            this.$el.append(bookView.render().el);
    }

    当我们给collection添加一个model的时候,如果绑定了collection的add事件,那么该事件的回调函数会接收三个参数。

    第一个参数是:当前被add到collection的model对象;

    第二个参数是:当前collection对象。

    第三个参数是可选项,具体是什么官方也没有介绍。

    其它的事件回调类似。以下附上官方事件列表。

    • "add" (model, collection, options) — when a model is added to a collection.
    • "remove" (model, collection, options) — when a model is removed from a collection.
    • "reset" (collection, options) — when the collection's entire contents have been replaced.
    • "sort" (collection, options) — when the collection has been re-sorted.
    • "change" (model, options) — when a model's attributes have changed.
    • "change:[attribute]" (model, value, options) — when a specific attribute has been updated.
    • "destroy" (model, collection, options) — when a model is destroyed.
    • "request" (model, xhr, options) — when a model (or collection) has started a request to the server.
    • "sync" (model, resp, options) — when a model (or collection) has been successfully synced with the server.
    • "error" (model, xhr, options) — when a model's save call fails on the server.
    • "invalid" (model, error, options) — when a model's validation fails on the client.
    • "route:[name]" (params) — Fired by the router when a specific route is matched.
    • "route" (router, route, params) — Fired by history (or router) when any route has been matched.
    • "all" — this special event fires for any triggered event, passing the event name as the first argument.
  • 相关阅读:
    全卷积网络(FCN)与图像分割
    Mac下编译tesseract报错 DotProductAVX can't be used on Android
    OSTU二值化算法
    ssh的用户配置文件config管理ssh会话
    SSD: Single Shot MultiBox Detector 编译方法总结
    论文笔记——A Deep Neural Network Compression Pipeline: Pruning, Quantization, Huffman Encoding
    LeetCode——Word Break
    C#多线程编程
    impinj 编程接口
    C# 委托实例(跨窗体操作控件)
  • 原文地址:https://www.cnblogs.com/maqunjing/p/3242451.html
Copyright © 2020-2023  润新知