mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-02 22:03:11 +02:00
✨ Ajax - fetch properties from object
This commit is contained in:
parent
b49980d169
commit
8a586fc32a
|
@ -25,6 +25,7 @@ import {
|
|||
generateId,
|
||||
findAncestorByAttrName,
|
||||
regexFilter,
|
||||
fetchFromObject,
|
||||
} from './lib/utils';
|
||||
import './lib/polyfills';
|
||||
|
||||
|
@ -1177,8 +1178,8 @@ class Choices {
|
|||
);
|
||||
} else {
|
||||
this._addChoice(
|
||||
result[value],
|
||||
result[label],
|
||||
fetchFromObject(result, value),
|
||||
fetchFromObject(result, label),
|
||||
result.selected,
|
||||
result.disabled,
|
||||
undefined,
|
||||
|
|
|
@ -602,4 +602,19 @@ export const reduceToValues = (items, key = 'value') => {
|
|||
}, []);
|
||||
|
||||
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