Last active
December 28, 2015 16:19
-
-
Save esvit/7527827 to your computer and use it in GitHub Desktop.
category edit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<select class="form-control" ng-model="item.category_id"> | |
<option ng-selected="!item.category_id">-</option> | |
<option value="{{ category.id }}" ng-repeat="category in categories" ng-selected="item.category_id == category.id"> | |
{{ category.prefix }}{{ category.title|language }} | |
</option> | |
</select> | |
CategoryResource.get(function (data) { | |
$scope.loading.categories = false; | |
var items = []; | |
function walk(item, level) { | |
// 2 space per level | |
if (level > 0) { // without root item | |
item.prefix = new Array((level - 1) * 2 + 1).join(String.fromCharCode(160)); | |
if (level > 1) { // only for childrens | |
item.prefix += '» '; | |
} | |
items.push(item); | |
} | |
for (var i = 0; i < item.children.length; i++) { | |
walk(item.children[i], level + 1); | |
} | |
} | |
walk(data, 0); | |
$scope.categories = items; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment