getByPathString<R> method
Retrieves a value of type R from the array using a string path.
The path is a '/'-separated string that navigates through nested ModelLess or
ModelLessArray structures.
If the path cannot be fully resolved, the method returns the provided default value.
path A '/'-separated string representing the navigation path.
def A default value of type R that is returned if the path
Implementation
R getByPathString<R>(String path, {dynamic def}) {
if (path.endsWith('/')) {
path = path.substring(0, path.length - 1);
}
if (path.startsWith('/')) {
path = path.substring(1, path.length);
}
List<dynamic> arr = <dynamic>[];
for (var element in Uri(path: path).pathSegments) {
arr.add(int.tryParse(element) ?? element);
}
return getByPath<R>(arr, def: def);
}