Should I be able to attach a click event to an item in the template for a scrollview?
No matter how simplified I make the template, there is always an error of "undefined is not a function" arises if I put a click event on any html item in the scrollview template. But the function is definitely in the view model. In fact of course putting a fake click method to invoke in the template generates the same error, so it leads me to think that the template is not bound to the viewModel.
<div data-role="view"
data-title="debug"
data-model="app.friendsService.viewModel"
data-stretch="true">
<div
id="toddlersScrollview"
data-role="scrollview"
data-items-per-page="6"
data-bind="source:friendsDS"
data-template="allfriends-template"
data-enable-pager="false"
style="height:200px;">
</div>
</div>
</div>
<script type="text/x-kendo-template" id="allfriends-template">
<div data-bind="click:onfriendClick"></div>
</script>
</div>
</div>
Viewmodel snippet:
function (global) {
var friendsViewModel,
app = global.app = global.app || {};
friendsViewModel = kendo.data.ObservableObject.extend({
roomid:null,
childid:null,
fname:null,
mname:null,
friendsDS:null,
onfriendClick: function(e) {
console.log("something");
},
friendsDS: new kendo.data.DataSource({
transport: {
read: {
url: "http://someurl.com/v1/room/param/children",
dataType: "json",
data: function() {
var roomid = app.friendsService.viewModel.get("roomid")
return {roomid: roomid};
},
type: "GET"
},
update: {
url: "http://acorn.xander.com/api/rooms",
type: "PUT"}
},
schema: {
model: { "id":"id",
fields: {
id: { type: "number" },
fname: { type: "string" },
mname: { type: "string" },
lname: { type: "string" }
}
}
}
})
});
app.friendsService = {
viewModel: new friendsViewModel()
};
})(window);
No matter how simplified I make the template, there is always an error of "undefined is not a function" arises if I put a click event on any html item in the scrollview template. But the function is definitely in the view model. In fact of course putting a fake click method to invoke in the template generates the same error, so it leads me to think that the template is not bound to the viewModel.
<div data-role="view"
data-title="debug"
data-model="app.friendsService.viewModel"
data-stretch="true">
<div
id="toddlersScrollview"
data-role="scrollview"
data-items-per-page="6"
data-bind="source:friendsDS"
data-template="allfriends-template"
data-enable-pager="false"
style="height:200px;">
</div>
</div>
</div>
<script type="text/x-kendo-template" id="allfriends-template">
<div data-bind="click:onfriendClick"></div>
</script>
</div>
</div>
Viewmodel snippet:
function (global) {
var friendsViewModel,
app = global.app = global.app || {};
friendsViewModel = kendo.data.ObservableObject.extend({
roomid:null,
childid:null,
fname:null,
mname:null,
friendsDS:null,
onfriendClick: function(e) {
console.log("something");
},
friendsDS: new kendo.data.DataSource({
transport: {
read: {
url: "http://someurl.com/v1/room/param/children",
dataType: "json",
data: function() {
var roomid = app.friendsService.viewModel.get("roomid")
return {roomid: roomid};
},
type: "GET"
},
update: {
url: "http://acorn.xander.com/api/rooms",
type: "PUT"}
},
schema: {
model: { "id":"id",
fields: {
id: { type: "number" },
fname: { type: "string" },
mname: { type: "string" },
lname: { type: "string" }
}
}
}
})
});
app.friendsService = {
viewModel: new friendsViewModel()
};
})(window);