mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-19 14:06:33 +02:00
✨ Ajax - fetch properties from object
This commit is contained in:
parent
b49980d169
commit
8a586fc32a
|
@ -25,6 +25,7 @@ import {
|
||||||
generateId,
|
generateId,
|
||||||
findAncestorByAttrName,
|
findAncestorByAttrName,
|
||||||
regexFilter,
|
regexFilter,
|
||||||
|
fetchFromObject,
|
||||||
} from './lib/utils';
|
} from './lib/utils';
|
||||||
import './lib/polyfills';
|
import './lib/polyfills';
|
||||||
|
|
||||||
|
@ -1177,8 +1178,8 @@ class Choices {
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this._addChoice(
|
this._addChoice(
|
||||||
result[value],
|
fetchFromObject(result, value),
|
||||||
result[label],
|
fetchFromObject(result, label),
|
||||||
result.selected,
|
result.selected,
|
||||||
result.disabled,
|
result.disabled,
|
||||||
undefined,
|
undefined,
|
||||||
|
|
|
@ -602,4 +602,19 @@ export const reduceToValues = (items, key = 'value') => {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch properties from object
|
||||||
|
* @param {Object} object Related object
|
||||||
|
* @param {String} properties Properties from object
|
||||||
|
*/
|
||||||
|
export const fetchFromObject = function (object, properties){
|
||||||
|
const index = properties.indexOf('.');
|
||||||
|
|
||||||
|
if(index > -1){
|
||||||
|
return fetchFromObject(object[properties.substring(0, index)], properties.substr(index + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
return object[properties];
|
||||||
|
};
|
Loading…
Reference in a new issue