Merge pull request #1895 from dpalou/MOBILE-3008
MOBILE-3008 core: Filter undefined in objectToArrayOfObjectsmain
commit
9b4da3e474
|
@ -52,7 +52,7 @@ export class CoreCourseSectionPage implements OnDestroy {
|
||||||
courseHandlers: CoreCourseOptionsHandlerToDisplay[];
|
courseHandlers: CoreCourseOptionsHandlerToDisplay[];
|
||||||
courseMenuHandlers: CoreCourseOptionsMenuHandlerToDisplay[] = [];
|
courseMenuHandlers: CoreCourseOptionsMenuHandlerToDisplay[] = [];
|
||||||
dataLoaded: boolean;
|
dataLoaded: boolean;
|
||||||
downloadEnabled: boolean;
|
downloadEnabled = false;
|
||||||
downloadEnabledIcon = 'square-outline'; // Disabled by default.
|
downloadEnabledIcon = 'square-outline'; // Disabled by default.
|
||||||
prefetchCourseData = {
|
prefetchCourseData = {
|
||||||
prefetchCourseIcon: 'spinner',
|
prefetchCourseIcon: 'spinner',
|
||||||
|
|
|
@ -977,14 +977,21 @@ export class CoreUtilsProvider {
|
||||||
objectToArrayOfObjects(obj: object, keyName: string, valueName: string, sortByKey?: boolean, sortByValue?: boolean): any[] {
|
objectToArrayOfObjects(obj: object, keyName: string, valueName: string, sortByKey?: boolean, sortByValue?: boolean): any[] {
|
||||||
// Get the entries from an object or primitive value.
|
// Get the entries from an object or primitive value.
|
||||||
const getEntries = (elKey, value): any[] | any => {
|
const getEntries = (elKey, value): any[] | any => {
|
||||||
if (typeof value == 'object') {
|
if (typeof value == 'undefined' || value == null) {
|
||||||
|
// Filter undefined and null values.
|
||||||
|
return;
|
||||||
|
} else if (typeof value == 'object') {
|
||||||
// It's an object, return at least an entry for each property.
|
// It's an object, return at least an entry for each property.
|
||||||
const keys = Object.keys(value);
|
const keys = Object.keys(value);
|
||||||
let entries = [];
|
let entries = [];
|
||||||
|
|
||||||
keys.forEach((key) => {
|
keys.forEach((key) => {
|
||||||
const newElKey = elKey ? elKey + '[' + key + ']' : key;
|
const newElKey = elKey ? elKey + '[' + key + ']' : key,
|
||||||
entries = entries.concat(getEntries(newElKey, value[key]));
|
subEntries = getEntries(newElKey, value[key]);
|
||||||
|
|
||||||
|
if (subEntries) {
|
||||||
|
entries = entries.concat(subEntries);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return entries;
|
return entries;
|
||||||
|
|
Loading…
Reference in New Issue