Skip to content

Instantly share code, notes, and snippets.

@vlas-ilya
Created October 12, 2015 16:05
Show Gist options
  • Save vlas-ilya/0217d4aba7faa0f5a6b5 to your computer and use it in GitHub Desktop.
Save vlas-ilya/0217d4aba7faa0f5a6b5 to your computer and use it in GitHub Desktop.
Правильный вариант
<!DOCTYPE html>
<html>
<head>
<title>Test Select form Matreshka</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<link href="http://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css" rel="stylesheet" />
<script src="http://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.min.js"></script>
<script src="http://cdn.jsdelivr.net/matreshka/latest/matreshka.min.js"></script>
</head>
<body>
<select multiple="multiple" id="mSelect" width="200px">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
<span type="text" id="selectSpan"/>
<script type="text/javascript">
$(document).ready(function () {
Matreshka.binders.select2 = function () {
return {
on: 'change',
getValue: function () {
return $(this).select2('val');
},
setValue: function (v) {
return $(this).select2('val', v);
},
initialize: function () {
$(this).select2();
}
}
}
// Matreshka.defaultBinders.unshift(function (element) {
// if ($(element).hasClass("select2")) {
// return Matreshka.binders.select2();
// }
// });
var mk = new Matreshka;
mk.bindNode('x', '#mSelect', Matreshka.binders.select2());
mk.bindNode('x', '#selectSpan', Matreshka.binders.innerHTML());
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment