jqwidgets-framework
Version:
jQWidgets is an advanced Angular, Vue, Blazor, React, Web Components, jquery, ASP .NET MVC, Custom Elements and HTML5 UI framework.
90 lines (82 loc) • 4.45 kB
HTML
<html lang="en">
<head>
<title id="Description">Integration of jqxDropDownList with Knockout</title>
<link rel="stylesheet" href="../../../jqwidgets/styles/jqx.base.css" type="text/css" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1 maximum-scale=1 minimum-scale=1" />
<script type="text/javascript" src="../../../scripts/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="../../../scripts/json2.js"></script>
<script type="text/javascript" src="../../../scripts/knockout-3.0.0.js"></script>
<script type="text/javascript" src="../../../jqwidgets/jqxcore.js"></script>
<script type="text/javascript" src="../../../jqwidgets/jqxbuttons.js"></script>
<script type="text/javascript" src="../../../scripts/demos.js"></script>
<script type="text/javascript" src="../../../jqwidgets/jqxscrollbar.js"></script>
<script type="text/javascript" src="../../../jqwidgets/jqxlistbox.js"></script>
<script type="text/javascript" src="../../../jqwidgets/jqxdata.js"></script>
<script type="text/javascript" src="../../../jqwidgets/jqxknockout.js"></script>
<script type="text/javascript" src="../../../jqwidgets/jqxcheckbox.js"></script>
<script type="text/javascript" src="../../../jqwidgets/jqxdropdownlist.js"></script>
<script type="text/javascript">
$(document).ready(function () {
// View Model
var listModel = function (items) {
this.items = ko.observableArray(items);
this.itemToAdd = ko.observable("");
this.disabled = ko.observable(false);
this.selectedIndex = ko.observable(1);
// adds new item.
this.addItem = function () {
if (this.itemToAdd() != "") {
this.items.push(this.itemToAdd()); // Adds the item. Writing to the "items" observableArray causes any associated UI to update.
this.itemToAdd(""); // Clears the text box, because it's bound to the "itemToAdd" observable
}
} .bind(this); // Ensure that "this" is always this view model
// removes item.
this.removeItem = function () {
this.items.pop();
}
// gets the selected index.
this.getIndex = function () {
alert("Selected Index: " + this.selectedIndex());
}
// sets the selected index.
this.setIndex = function () {
this.selectedIndex(1);
}
};
ko.applyBindings(new listModel(["Caffé Latte", "Cortado", "Espresso"]));
});
</script>
</head>
<body style='font-size: 13px; font-family: Verdana;' class='default'>
<form data-bind="submit: addItem">
<div>
<div>
<p>
Your Items</p>
<div id="list" data-bind="jqxDropDownList: {source: items, disabled: disabled, selectedIndex: selectedIndex, autoDropDownHeight: true, height: 25, width: 200,}">
</div>
</div>
<div style="margin-top: 10px;">
New item:
<input data-bind='value: itemToAdd, valueUpdate: "afterkeydown"' />
<button id="addButton" data-bind="jqxButton: {}" type="submit">
Add</button>
<button id="removeButton" data-bind="click: removeItem, jqxButton: {}">
Remove</button>
</div>
<div style="margin-top: 10px;">
<button data-bind="click: setIndex, jqxButton: {}" id="setButton">
Select Index</button>
<button data-bind="click: getIndex, jqxButton: {}" id="getButton">
Get Selected Index</button>
</div>
<div data-bind="jqxCheckBox: {checked: disabled}" style='margin-top: 5px;' id="checkBox">Disabled</div>
</div>
</form>
<div style="position: absolute; bottom: 5px; right: 5px;">
<a href="https://www.jqwidgets.com/" alt="https://www.jqwidgets.com/"><img alt="https://www.jqwidgets.com/" title="https://www.jqwidgets.com/" src="https://www.jqwidgets.com/wp-content/design/i/logo-jqwidgets.png"/></a>
</div>
</body>
</html>