function ancestorsCategories(parentId, categories) {

							var category = categories.filter(function(val) {

								return val._id === parentId;
							});
							if( !Array.isArray(category) ) throw new SyntaxError("Не массив");
							category = category[0];
							if(typeof category !== "object") throw new SyntaxError("Не обьект");

							var ancestorsId = [];
							ancestorsId.push(parentId)
							ancestorsId = ancestorsId.concat(category.ancestors);

							var ancestors = categories.filter(function(val) {

								return ancestorsId.some(function(k) { return k === val._id; });
							});

							ancestors.forEach(function(val) {

								var ancestor = {};
								ancestor.name = val.name;
								ancestor.state = 'categories({subcategory: "' +val._id+ '"})';
								scope.states.push( ancestor );
							});
							//console.log(ancestors);
						}
/*
		            	 * @name   ancestorsCategories
						 * @param  {String} Category.parentId.
						 * @push   add scope.states array ancestorsCategories
						 */
@name   ancestorsCategories
@param  {String} Category.parentId.
@push   add scope.states array ancestorsCategories
@name ancestorsCategories @param { String } Category . parentId . @push add scope . states array ancestorsCategories
function ancestorsCategories(parentId, categories) {
							var category = categories.filter(function(val) {
								return val._id === parentId;
							});
							if( !Array.isArray(category) ) throw new SyntaxError("Не массив");
							category = category[0];
							if(typeof category !== "object") throw new SyntaxError("Не обьект");
							var ancestorsId = [];
							ancestorsId.push(parentId)
							ancestorsId = ancestorsId.concat(category.ancestors);
							var ancestors = categories.filter(function(val) {
								return ancestorsId.some(function(k) { return k === val._id; });
							});
							ancestors.forEach(function(val) {
								var ancestor = {};
								ancestor.name = val.name;
								ancestor.state = 'categories({subcategory: "' +val._id+ '"})';
								scope.states.push( ancestor );
							});
						}
function ancestorsCategories ( parentId , categories ) { var category = categories . filter ( function ( val ) { return val . _id === parentId ; } ) ; if ( ! Array . isArray ( category ) ) throw new SyntaxError ( "Не массив"); category = category [ 0 ] ; if ( typeof category !== "object" ) throw new SyntaxError ( "Не обьект"); var ancestorsId = [ ] ; ancestorsId . push ( parentId ) ancestorsId = ancestorsId . concat ( category . ancestors ) ; var ancestors = categories . filter ( function ( val ) { return ancestorsId . some ( function ( k ) { return k === val . _id ; } ) ; } ) ; ancestors . forEach ( function ( val ) { var ancestor = { } ; ancestor . name = val . name ; ancestor . state = 'categories({subcategory: "' + val . _id + '"})' ; scope . states . push ( ancestor ) ; } ) ; }
@name   ancestorsCategories
 @param  {String} Category.parentId.
@name ancestorsCategories @param { String } Category . parentId .
//console.log(ancestors);