Skip to content

Instantly share code, notes, and snippets.

@esvit
Last active December 28, 2015 16:19
Show Gist options
  • Save esvit/7527827 to your computer and use it in GitHub Desktop.
Save esvit/7527827 to your computer and use it in GitHub Desktop.
category edit
<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