Array length issue on initailize extend

When array length issue occurred check the error and find out where the error the extend the child view and give the code to correct the condition not get the array empty.

childViews: _.extend(FacetsBrowseView.prototype.childViews, {
		'Facets.FacetedNavigation': function(options) {
			var exclude = _.map((options.excludeFacets || '').split(','), function (facet_id_to_exclude) {
				return jQuery.trim(facet_id_to_exclude);
			})
				, has_categories = !!(this.category && this.category.categories)
				, has_items = _.isEmpty(this.model.get('items')) ? 0 : this.model.get('items').length
				, has_facets = has_items && this.model.get('facets').length
				, applied_facets = this.translator.cloneWithoutFacetId('category').facets
				, has_applied_facets = applied_facets.length;
			return new FacetsFacetedNavigationView({
				categoryItemId: this.category && this.category.itemid
				, clearAllFacetsLink: this.translator.cloneWithoutFacets().getUrl()
				, hasCategories: has_categories
				, hasItems: has_items
				// facets box is removed if don't find items
				, hasFacets: has_facets
				, hasCategoriesAndFacets: has_categories && has_facets
				// Categories are not a real facet, so lets remove those
				, appliedFacets: applied_facets
				, hasFacetsOrAppliedFacets: has_facets || has_applied_facets
				//,	translatorUrl: this.translator.getUrl()
				, translator: this.translator
				//,	translatorConfig: this.options.translatorConfig
				, facets: _.filter(this.model.get('facets'), function (facet) {
					return !_.contains(exclude, facet.id);
				})
				, totalProducts: this.model.get('total')
				, keywords: this.translator.getOptionValue('keywords')
			});
		},
		'Facets.Items': function () {
			var self = this
				, display_option = _.find(this.itemsDisplayOptions, function (option) {
					return option.id === self.translator.getOptionValue('display');
				});
			return new BackboneCollectionView({
				childTemplate: display_option.template
				, childView: FacetsItemCellView
				, childViewOptions: {
					application: this.application
				}
				, viewsPerRow: parseInt(display_option.columns, 10)
				, collection: _.isEmpty(this.model.get('items')) ? {} : this.model.get('items')
				, cellTemplate: facets_items_collection_view_cell_tpl
				, rowTemplate: facets_items_collection_view_row_tpl
				, template: facets_items_collection_tpl
				, context: {
					keywords: this.translator.getOptionValue('keywords')
				}
			});
		},
		'GlobalViews.Pagination': function()
		{
			var translator = this.translator;			
			return new GlobalViewsPaginationView(_.extend({
				currentPage: translator.getOptionValue('page')
			,	totalPages:  _.isEmpty(this.totalPages) ? 0 : this.totalPages
			,	pager: function (page) {
				return translator.cloneForOption('page', page).getUrl();
				}
			}, Configuration.defaultPaginationSettings)
			);							
		}
	})

Leave a comment

Your email address will not be published. Required fields are marked *