newbie to kendo
The kendo datasource only returns arrays and my RESTful api returns a client as an array of one element.
However, I cannot seem to bind the 'Name' field of the client to an html input box.
I can however consume the data if I put it in a 'ul', as shown in the below code. I know the json response is well formed because I can console.log(obj[0].Name);
I attempted to return obj[0] in the data: of the datasource but that just broke everything. (no slice error message, as it tries to slice up the array).
I'm sure this is easy but I must be just thinking about this all wrong...
Html and js below:
<div data-role="view" data-title="Client Detail" data-model="app.clientView">
<!-- this does not work -->
<input data-bind="value: app.clientView.data"/>
<input data-bind="value: app.clientView.data[0].Name"/>
<input data-bind="value: app.clientView.data.Name"/>
<!-- this works -->
<ul data-role="listview" data-source="app.clientView.data" data-template="client-template"></ul>
<script type="text/x-kendo-template" id="client-template">
<a href="components/clientView/view.html?id=#: ID #">
<div>#: Name #</div>
<div>#: LastActivityOn #</div>
</a>
</script>
app.clientView = kendo.observable({
data: new kendo.data.DataSource({
transport: {
read: {
url: app.uri + "clients/69", //+ id,
type: "get",
dataType: "json",
beforeSend: function (req) {
req.setRequestHeader('X-authKey', app.key);
}
}
},
schema: {
data: function (response) {
console.log(response);
var obj = $.parseJSON(response);
console.log(obj[0].Name);
return obj;
}
}
})
});