From e60be87a94ec7a93921d0b86bd50aad5cc7f0fa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Egon=20Rich=C3=A1rd=20T=C5=91r=C3=B6s?= Date: Mon, 19 Mar 2018 11:46:28 +0100 Subject: [PATCH] :ambulance: Add example --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index d6ecdc3..36641ec 100644 --- a/README.md +++ b/README.md @@ -867,6 +867,24 @@ example.ajax(function(callback) { }); ``` +**Example 2:** +If your structure differs from `data.value` and `data.key` syntax you can write your own `key` and `value` into the `callback` function. This could be useful when you don't want to transform the given response. + +```js +const example = new Choices(element) + +example.ajax(function(callback) { + fetch(url) + .then(function(response) { + response.json().then(function(data) { + callback(data, 'data.key', 'data.value'); + }); + }) + .catch(function(error) { + console.log(error); + }); +}); +``` ## Browser compatibility Choices is compiled using [Babel](https://babeljs.io/) to enable support for [ES5 browsers](http://caniuse.com/#feat=es5). If you need to support a browser that does not support one of the features listed below, I suggest including a polyfill from the very good [polyfill.io](https://cdn.polyfill.io/v2/docs/):