i have this code
var path = App.request('app:page:breadcrumb', index);
if(parseVals) {
path[ path.length - 1 ].title = this._parseVals(path[ path.length - 1 ].title, parseVals);
}
this.BreadCrumbView.collection.reset(path);
the path variable is the return of this function
getBreadcrumbs: function(index, getCollection){
// return empty collections of index set to null and get collection flagged to true
if(! index && getCollection){
return new Breadcrumbs.Collection({});
}
// Generate breadcrumbs object
var breadcrumbArr = Server.adminPages[index]['breadcrumb_path'].split('/'),
breadcrumbs = _.values(array_intersect_key(Server.adminPages ,array_flip(breadcrumbArr)));
// Set selected breadcrumb
$.each(breadcrumbs, function(index){
breadcrumbs[index]['is_active'] = index == breadcrumbs.length - 1;
});
// Return breadcrumbs as collection or object
return getCollection
? new Breadcrumbs.Collection(breadcrumbs)
: breadcrumbs;
},
My problem is that this "path" variable is acually a breadcrumb array, and every time i modify the "path" variable, its acually modifing the global Server.adminPages variable, i tried couple of thinks to clone this object like:
- [].concat(Server.adminPages[index])
- $.extend({}, Server.adminPages[index])
- Server.adminPages[index].splice(0)
- jquery $.each()
None of the above worked its just keep to change the global variable if its matter, the adminPages code is hard Coded in the html header
some background.. the path array contain some mustache variables like {{action}} , to determine when the page is in edit state or create state. the problem is that if i will navigate to "Create" action, the mustache will be parsed to "Create" , than if i will navigate to edit since the "path" variable was already changed ( or w/e the js was doing there ) i will still see "Create" because the {{action}} string was already parsed