# j-DataSource

> The component loads data from the external source via AJAX() method and it binds the value according to the config.path.

Framework: jcomponent20
Product: jComponent 20 (jcomponent@20)
Language: en
Content-SHA256: 9f6c58aecb899aeb714d265b23ace97db8e569e98b0aa09f29f47187b0087efb
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: components@910ed1a86f6e72b4f031d3ad0dc7844f9fc5cb8e
Review: not-recorded

The component loads data from the external source via `AJAX()` method and it binds the value according to the `config.path`.


__Configuration__:

- `path {String}` __required__ a path where the value will be set
- `url {String}` optional, a URL address for obtaining data
- `delay {Number}` optional, a delay (in milliseconds) for obtaining data (defaul: `0`)

__Good to know__:

- `config.path = '#codelist'` sets a value in code lists `DEF.cl.codelist`
- `config.path = '%codelist'` sets a value in as temporary
- `config.path = '?.path` sets a value according to the plugin path
- `config.path = 'absolute.path` sets a value according to the path

__Can I use dynamic URL address?__

Yes, you can use `<ui-component name="datasource" path="..."` for dynamic obtaining of data.

```html
<ui-component name="datasource" path="?.urlcities" config="path:#cities"></ui-component>
```

__How can I modify data before binding?__

```html
<ui-component name="datasource" config="url:https://www.yourdomain.com/api/countries/;path:#countries">
	<script type="text/plain">
		var output = [];
		for (var item of value)
			output.push({ id: item.Id, name: item.Name });
		return output;
	</script>
</ui-component>
```

Use it with `<ui-component name="datasource">`. When the component is not loaded yet, jComponent downloads it on first use from the address in `DEF.fallback` (the Componentator CDN by default). Author: Peter Širka. Source: the Componentator components repository, MIT license.

```html example.html
<ui-component name="datasource" config="url:https://www.totaljs.com/dashboard.json;path:#mycodelist">
	<script type="text/plain">
		return value.children;
	</script>
</ui-component>

<ui-bind path="#mycodelist" config="html pre:JSON.stringify(value, null, '  ')" class="block">
	<pre></pre>
</ui-bind>
```
