Nested ng-repeat in the same array level
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Create a filter that splits your array in groups of three and nest the groups. The filter should be something like this: app.filter('split', function() {
return function(target) {
var splitted = [];
if (!target) {
return target;
}
for(var i = 0; i < target.length; i += 3) {
splitted.push(target.slice(i, i+3));
}
return splitted;
}
});
$scope.original = [1, 2, 3, 4, 5, 6, 7, 8, 9];
<div ng-repeat="group in original | split">
<div ng-repeat="item in group">{{item}}</div>
<div class="clear"></div>
</div>
|
Iterate properties and nested first level properties
Tag : chash , By : James Dio
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , FlattenHierarchy does not do what you think it does, and instead follows the inheritance hiearchy for static members. If you'd like to get sub-properties for objects, you'll need to do that yourself: static IEnumerable<PropertyInfo> FlattenProperties(Type type)
{
// Assumption #1: you do not want "simple" types enumerated
if (!type.IsClass)
return Enumerable.Empty<PropertyInfo>();
// Assumption #2: you want to ignore "the usual suspects"
if (type.Namespace != null && type.Namespace.StartsWith("System"))
return Enumerable.Empty<PropertyInfo>();
// Assumption #3: your class hierarchy won't destroy recursion
// Assumption #4: you simply want the PropertyInfo
return type.GetProperties(BindingFlags.FlattenHierarchy
| BindingFlags.Instance
| BindingFlags.Public)
.SelectMany(pi => new[] { pi }
.Concat(FlattenProperties(pi.PropertyType)));
}
// Replace Assumptions #1 and #2 above with this:
// Assumption #5: given interface ISomething { }
if (!typeof(ISomething).IsAssignableFrom(type))
return Enumerable.Empty<PropertyInfo>();
static IEnumerable<IEnumerable<PropertyInfo>> FlattenProperties(
Type type,
IEnumerable<PropertyInfo> ancestors = null)
{
// change to Assumptions #1/#2 or #5 to yield break
// ...
ancestors = ancestors ?? Enumerable.Empty<PropertyInfo>();
var properties = type.GetProperties(
BindingFlags.FlattenHierarchy
| BindingFlags.Instance
| BindingFlags.Public);
foreach (var property in properties)
{
// again, Assumption #3: your class hierarchy won't destroy recursion
// Assumption #6: you actually want the initial nested property too
yield return ancestors.Concat(new[] { property });
foreach (var nested in FlattenProperties(
property.PropertyType,
ancestors.Concat(new [] { property })))
{
yield return nested;
}
}
}
// foreach (var tree in FlattenProperties(typeof(Car)))
// {
// Console.WriteLine("{0}", String.Join(".", tree.Select(pi => pi.Name)));
// }
CarId
Description
Engine
Engine.EngineId
Engine.Description
|
angular nested ng-repeat not working on third level
Date : March 29 2020, 07:55 AM
this one helps. I am using the following nested ng-repeat , You have a typo in the ng-repeat, you're missing the =: <ul ng-repeat="image in exercise.images">
<li>{{image}}</li>
</ul>
|
Angular JS nested ng-repeat of only one top-level object?
Date : March 29 2020, 07:55 AM
may help you . You can use the filter filter for this (assume here that theOrder is a scope variable with the order number that you want): <div ng-repeat="order in orders | filter:{ordernum: theOrder}">
function OrderController($scope) {
$scope.orders = [{
ordernum: 3,
parcels: [{
upid: 9
}, {
upid: 15
}]
}, {
ordernum: 7,
parcels: [{
upid: 1
}]
}];
$scope.theOrder = 3;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.20/angular.min.js"></script>
<div ng-app="" ng-controller="OrderController">
<select ng-model="theOrder">
<option value="{{order.ordernum}}"
ng-repeat="order in orders">{{order.ordernum}}</option>
</select>
<div ng-repeat="order in orders | filter:{ordernum: theOrder}">
order {{order.ordernum}}
<div ng-repeat="parcel in order.parcels">
{{parcel.upid}}
<div ng-repeat="sku in parcel.skus">
{{sku.sku}}{{sku.commodity}}
</div>
</div>
</div>
</div>
|
Nested ng-repeat in Angularjs displayed at the same level
Date : March 29 2020, 07:55 AM
wish of those help What's the purpose of it? A < div> inside a < span> is considered bad practice and I'd advise you to change your CSS if appropriate. There may be a good reasoning for it though, but this question doesn't give enough details for an answer. And coming to your above problem it can be achieved by creating another array consists of buttons like below. $scope.navigation= [{ "id": "A", "buttons": [{ "id": "A1" }, { "id": "A2" }] },
{ "id": "B", "buttons": [{ "id": "B1" }, { "id": "B2" }] }];
$scope.buttons = [];
angular.forEach($scope.navigation, function (tab) {
angular.forEach(tab.buttons, function (button) {
$scope.buttons.push(button);
});
});
<div> <div data-ng-repeat="button in buttons">{{button.id}}</div> </div>
|