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

Using Schema on child collections

2 Answers 22 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Stacey
Top achievements
Rank 1
Stacey asked on 11 Nov 2013, 10:08 PM
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 Answers, 1 is accepted

Sort by
0
Stacey
Top achievements
Rank 1
answered on 11 Nov 2013, 11:17 PM
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"
0
Petur Subev
Telerik team
answered on 13 Nov 2013, 01:10 PM
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!
Tags
MVVM
Asked by
Stacey
Top achievements
Rank 1
Answers by
Stacey
Top achievements
Rank 1
Petur Subev
Telerik team
Share this question
or