I was following the Daniel tip, how to achieve inheritance with MVVM. But I am getting strange errors in jquery when using mouseover/out in ListView template.
How can I achieve this?
7 Answers, 1 is accepted
The problem comes from the fact that products datasource is not observed correctly in this case correctly. You will need to call the ObservableObject init method in order to resolve this issue. Check the updated demo:
Regards,
Georgi Krustev
Telerik
This is great, but how can I add some fields to viewModel?
This is not working:
var
viewModelBase = kendo.data.ObservableObject.extend({
init:
function
() {
kendo.data.ObservableObject.fn.init.call(
this
,
this
);
},
isVisible:
true
,
onSave:
function
(e) {
kendoConsole.log(
"event :: save("
+ kendo.stringify(e.model,
null
, 4) +
")"
);
},
products:
new
kendo.data.DataSource({
schema: {
model: {
id:
"ProductID"
}
},
batch:
true
,
transport: {
read: {
dataType:
"jsonp"
},
parameterMap:
function
(options, operation) {
if
(operation !==
"read"
&& options.models) {
return
{models: kendo.stringify(options.models)};
}
}
}
}),
onMouseClick:
function
() {
kendoConsole.log(
"event :: click"
);
},
onMouseOver:
function
()
{
kendoConsole.log(
"event :: mouseover"
);
},
onMouseOut:
function
()
{
kendoConsole.log(
"event :: mouseout"
);
}
});
var
viewModel =
new
viewModelBase({
test:
"bla"
});
"test" is not bind to anything. For example <div data-bind="html: test"></div> does not print "bla".Hello Matjaž,
the object you are passing a parameter in the constructor of the viewmodel instance should be handled in the init method of the observable object descendant - right now it its fields are not assigned anywhere in order to be subsequently bound to.
I would also like to ask you to use your newly created support account
admin@d****.eu with the transferred license, as the current one no longer has an associated active support.
Petyo
Telerik
var
viewModelBase = kendo.data.ObservableObject.extend({
field1:
"some test"
,
init:
function
(options) {
kendo.data.ObservableObject.fn.init.call(
this
, options);
},
but then field1 is not recognized by MVVM.
Hello Matjaž,
this approach won't work for sure. Please check my previous reply - you need to assign the fields from the received parameter to your own object.
Regards,Petyo
Telerik
I know.
Last question. Would this be ok?
init:
function
(options)
{
kendo.data.ObservableObject.fn.init.call(
this
, $.extend(
this
, options));
},
Or it would be better to avoid that and just init fields in init method?
Hello Matjaž,
$.extend(this, options) does pretty much what it says. It may do the trick for your case.
Regards,Petyo
Telerik