data-template - binding to null collection

3 posts, 1 answers
  1. Bilal
    Bilal avatar
    109 posts
    Member since:
    Oct 2014

    Posted 10 Feb 2015 Link to this post

    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, 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?


  2. Answer
    Nikolay Rusev
    Nikolay Rusev avatar
    2275 posts

    Posted 12 Feb 2015 Link to this post

    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. "

    Nikolay Rusev
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Leandro
    Leandro avatar
    7 posts
    Member since:
    Apr 2011

    Posted 05 Jun 2015 in reply to Nikolay Rusev Link to this post

    Try this:

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

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

Back to Top