Using Schema on child collections

3 posts, 0 answers
  1. Stacey
    Stacey avatar
    56 posts
    Member since:
    Aug 2013

    Posted 11 Nov 2013 Link to this post

    I have a situation where I want to attach a persistent function to child objects of a view model after they are passed to the view model from the server, so ...

    I am fetching it through a dataSource, that goes to the Kendo Multi-Select widget. The data looks like this ...

    {
      Name: "Some Object",
      Other: "Some other Properties",
      Tags: [
        {
          Name: "Tag1",
        },
        {
          Name: "Tag2",
        }
      ]
    But I would like for it to look like this, once it is in my javascript.

    {
      Name: "Some Object",
      Other: "Some other Properties",
      Tags: [
        {
          Name: "Tag1",
          onDelete: function(e){
            //somethinghappens;
          }
        },
        {
          Name: "Tag2",
          onDelete: function(e){
            //somethinghappens;
          }
        }
      ]
    Is there anything I can do to achieve this? I was looking at the "schema" feature of the dataSource.
  2. Stacey
    Stacey avatar
    56 posts
    Member since:
    Aug 2013

    Posted 11 Nov 2013 Link to this post

    I am fetching it much like this, on a grid; the url returns a flat JSON object from my database. It is at this point that I would like to be able to apply a schema so that the functions I need are part of the child objects.

    dataSource: {
        transport: {
            read: {
                url: url,
                dataType: "json",
                type: 'GET'
            }
        },
        schema: {
            total: "total",
            data: "data"
        },
        page: 0,
        pageSize: 15,
        take: 15,
        serverPaging: true,
        serverFiltering: true,
        type: "aspnetmvc-ajax"
    },
    pageable: {
        refresh: true,
        pageSizes: true
    },
    selectable: "row"
  3. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 13 Nov 2013 Link to this post

    Hello Stacey,

    Did you try the schema.parse function? It allows not only to parse some fields but I guess you should be able to dynamically attach other fields to the model.

    http://docs.kendoui.com/api/framework/datasource#configuration-schema.parse

    I hope this suits your needs.

    Kind Regards,
    Petur Subev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top