1
0
mirror of synced 2024-11-26 23:06:02 +03:00
select2/playground/basic/adapters.html

99 lines
2.2 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>QUnit Example</title>
<link href="../../dist/css/select2.css" rel="stylesheet"/>
<script src="../../vendor/almond-0.2.9.js" type="text/javascript"></script>
<script src="../../vendor/jquery-2.1.0.js" type="text/javascript"></script>
<script src="../../dist/js/select2.js"></script>
</head>
<body>
<select style="width:300px" id="array-single"></select>
<br />
<select style="width:300px" id="array-multiple" multiple="multiple"></select>
<br />
2014-08-31 05:14:46 +04:00
<select style="width:300px" id="remote-single"></select>
<br />
<select style="width:300px" id="remote-multiple" multiple="multiple"></select>
<script>
2014-08-31 05:14:46 +04:00
require(["select2/core", "select2/data/array", "select2/data/ajax"],
function (Select2, ArrayAdapter, AjaxAdapter) {
var arrayData = [
{
id: 0,
text: 'enhancement'
},
{
id: 1,
text: 'bug'
},
{
id: 2,
text: 'duplicate'
},
{
id: 3,
text: 'invalid'
},
{
id: 4,
text: 'wontfix'
}
];
var arraySingle = new Select2($("#array-single"), {
dataAdapter: ArrayAdapter,
data: arrayData
});
var arrayMultiple = new Select2($("#array-multiple"), {
dataAdapter: ArrayAdapter,
data: arrayData
});
2014-08-31 05:14:46 +04:00
var ajaxSettings = {
url: "https://api.github.com/search/repositories",
dataType: "json",
data: function (params) {
return {
q: "test"
}
},
processResults: function (data) {
var results = $.map(data.items, function (d) {
return {
id: d.id,
text: d.full_name
}
});
return results
}
};
var ajaxSingle = new Select2($("#remote-single"), {
dataAdapter: AjaxAdapter,
ajax: ajaxSettings
});
var ajaxMultiple = new Select2($("#remote-multiple"), {
dataAdapter: AjaxAdapter,
ajax: ajaxSettings
});
});
</script>
</body>
</html>