Defining Schema for Custom Objects

4 posts, 0 answers
  1. Brian
    Brian avatar
    32 posts
    Member since:
    Jun 2015

    Posted 14 Jan Link to this post

    Something is not clicking for me on this, and I am not really sure where to start.  I have what amounts to a directory structure I am sending from the server (see json below) and trying to load into the treeview.  However, I am getting an error stating .  Everything I have been able to find on that pretty much says that I need to define the schema.  This is taking too long for me to figure out and any help would be appreciated.

     

    01.{
    02.  "FolderId": 1,
    03.  "Name": "root",
    04.  "Description": "root description",
    05.  "Note": "root note",
    06.  "Parent": null,
    07.  "Children": [
    08.    {
    09.      "$id": "1",
    10.      "FolderId": 2,
    11.      "Name": "Sub Level 1",
    12.      "Description": "Sub Level 1 description",
    13.      "Note": "Sub Level 1 note",
    14.      "Children": [],
    15.      "Documents": [
    16.        {
    17.          "$id": "2",
    18.          "DocumentId": 2,
    19.          "Name": "PepsiCo Medical Test Doc with picture.docx",
    20.          "Note": "Copied from Document.Version 1.1",
    21.          "Description": null,
    22.          "DocType": 1,
    23.          "Status": 3,
    24.          "AllVersions": [],
    25.          "DocumentHistories": [],
    26.          "ViewingRoles": null,
    27.          "CurrentUserId": "00000000-0000-0000-0000-000000000000",
    28.          "Versions": [],
    29.          "PublishedVersion": null,
    30.          "LatestDraftVersion": null,
    31.          "LatestVersion": null,
    32.          "Disposed": false
    33.        }
    34.      ],
    35.      "Disposed": false
    36.    },
    37.    {
    38.      "$id": "3",
    39.      "FolderId": 3,
    40.      "Name": "Sub Level 2",
    41.      "Description": "Sub Level 2 description",
    42.      "Note": "Sub Level 2 note",
    43.      "Children": [
    44.        {
    45.          "$id": "4",
    46.          "FolderId": 4,
    47.          "Name": "Sub Level 2_1",
    48.          "Description": "Sub Level 2_1 description",
    49.          "Note": "Sub Level 2_1 note",
    50.          "Children": [],
    51.          "Documents": [
    52.            {
    53.              "$id": "5",
    54.              "DocumentId": 1,
    55.              "Name": "PepsiCo Medical Test Doc with picture.docx",
    56.              "Note": null,
    57.              "Description": null,
    58.              "DocType": 1,
    59.              "Status": 2,
    60.              "AllVersions": [],
    61.              "DocumentHistories": [],
    62.              "ViewingRoles": null,
    63.              "CurrentUserId": "00000000-0000-0000-0000-000000000000",
    64.              "Versions": [],
    65.              "PublishedVersion": null,
    66.              "LatestDraftVersion": null,
    67.              "LatestVersion": null,
    68.              "Disposed": false
    69.            }
    70.          ],
    71.          "Disposed": false
    72.        }
    73.      ],
    74.      "Documents": [],
    75.      "Disposed": false
    76.    }
    77.  ],
    78.  "Documents": [],
    79.  "Disposed": false
    80.}
  2. Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    1055 posts

    Posted 16 Jan Link to this post

    Hi Brian,

    Attached you will find a small sample which implements an MVC project scenario based on the data shared. In order to populate the TreeView I have passed the data to the widget using the ViewBag object. I have also used the BindTo() configuration method, which I have defined the proper bindings for the items. The Folders have both their Text and Children configured, while the Documents have only their Text configured (they have no children). The key point here is that each Folder should keep its children (Folders or Documents) always in the same field.

    Regards,
    Veselin Tsvetanov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Brian
    Brian avatar
    32 posts
    Member since:
    Jun 2015

    Posted 16 Jan in reply to Veselin Tsvetanov Link to this post

    Thank you!  How does it work with (in this case) a folder that has both folders and documents as children?
  4. Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    1055 posts

    Posted 18 Jan Link to this post

    Hello Brian,

    The required could be achieved if the following two conditions are met:

    - The FolderModel inherits from DocumentsModel. This way an explicit conversion form DocumentModel to FolderModel will be present:
    public class FolderModel : DocumentModel

    - The Children mapping is altered to represent the condition to chose between the two properties in the model:
    mappings.For<FolderModel>(binding => binding
        .ItemDataBound((item, folder) =>
        {
            item.Text = folder.Name;
        })
        .Children(folder => folder.Children != null ? folder.Children : folder.Documents)
    );

    Attached you will find a modified version of the discussed implementing the above.

    Regards,
    Veselin Tsvetanov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top