This is a migrated thread and some comments may be shown as answers.

data-template - binding to null collection

2 Answers 67 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Bilal
Top achievements
Rank 2
Bilal asked on 10 Feb 2015, 01:17 PM
Hello,
I have a "selectedProject" property on a ViewModel. This property is initially defined as "null". Eventually, this property will be set to an instance of an object locally defined as kendo.data.Model, having an array of "users".

Now, I am adding the following:
<div data-template="row-user-info-template" data-bind="source: selectedProject.users"></div>

Initially the selectedProject is null and hence users is undefined. That's why I am getting this exception:
"Uncaught TypeError: undefined has no properties"

Any idea how to workaround this issue?

Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay Rusev
Telerik team
answered on 12 Feb 2015, 09:08 AM

Hello Bilal,

We've already discussed this in the support thread. Please avoid duplication of posts. 

Bellow I'm quoting mu post in the above mentioned support thread.

"If `selectedProject` is null you are accessing property of object which is null. That said it is expected to have error thrown and you should make sure that when selectedProject variable is instantiated before accessing it. "

Regards,
Nikolay Rusev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Leandro
Top achievements
Rank 1
answered on 05 Jun 2015, 09:25 PM

Try this:

var viewModel = kendo.observable({
       selectedProject: []
    });

    kendo.bind($("body"), viewModel);

Tags
General Discussions
Asked by
Bilal
Top achievements
Rank 2
Answers by
Nikolay Rusev
Telerik team
Leandro
Top achievements
Rank 1
Share this question
or