从另一个视图运行主干视图初始化功能

时间:2018-07-17 11:20:16

标签: javascript backbone.js backbone-views backbone-events backbone-collections

我需要在另一个视图中执行此Backbone视图的initialize函数,以获取集合并再次呈现它,但是我不确定如何执行此操作?

这是带有初始化功能的视图,我需要在另一个Backbone视图中运行:

Checkout.Views.ShippingTypes = Backbone.View.extend({
   el: null,

   initialize: function(options) {
     // Get the seller_id
     this.seller_id = options.seller_id;
     this.company = options.company;
     this.premium = options.premium;
     this.address = options.address;
     this.postcode = options.postcode;
     this.payment_method = $('#payment-methods').find('li.selected-method').find('input.payment-name').val();

     // When fetching is done call the addAll function to start the rendering process
    this.listenTo(this.collection, 'reset', this.addAll);

    // Fetch the data for shipping types
    if (!App.isObject(Checkout.shippingMethods)) {
       Checkout.shippingMethods = {};
    }

    if (Checkout.shippingMethods[this.seller_id] && Checkout.shippingMethods[this.seller_id].readyState < 4) {
        Checkout.shippingMethods[this.seller_id].abort();
    }

    Checkout.shippingMethods[this.seller_id] = this.collection.fetch({
        reset: true,
        data: {
            company: this.company,
            premium: this.premium,
            shipping: Checkout.selectedShippingMethod,
            address: this.address,
            postcode: this.postcode,
            is_shipping_selected: Checkout.isShippingSelected || false,
            payment_method: this.payment_method
        }
    });
  }
});

0 个答案:

没有答案