Kendo UI DataSource & Knockout
by stratdaz
HTML
<script src="http://cdn.kendostatic.com/2011.3.1407/js/kendo.all.min.js"></script>
<link rel="stylesheet" href="http://cdn.kendostatic.com/2011.3.1407/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2011.3.1407/styles/kendo.default.min.css">
<script src="http://demos.kendoui.com/content/web/integration/knockout-1.2.1.js"></script>
<input id="autoComplete" />
CSS
body{
font:normal 1em/1.1em Arial,sans-serif;
padding:20px;
}
ol{
list-style:decimal outside none;
margin:5px 30px;
}
h3{
font-size:1.25em;
font-weight:bold;
}
.k-autocomplete {
width: 400px;
}
JavaScript
$("#autoComplete").kendoAutoComplete({
minLength:2,
dataTextField:"postalcode",
dataSource: new kendo.data.DataSource({
transport: {
read: {
url: "http://api.geonames.org/postalCodeSearchJSON?country=AU&postalcode_startsWith=406",
//url: function () {
// return "http://api.geonames.org/postalCodeSearchJSON?postalcode_startsWith=406";
//},
data: {
q: function(){
return $("#autoComplete").data("kendoAutoComplete").value();
},
maxRows: 10,
username: "stratdaz"
}
}
},
schema: {
data:"geonames"
}
}),
change: function(){
this.dataSource.read();
}
});