dataSource filter, then return data deeper in object

1 posts, 0 answers
  1. Vince
    Vince avatar
    1 posts
    Member since:
    Sep 2012

    Posted 20 Sep 2012 Link to this post

    I have an object with data I that I want to use to fill a list. When someone clicks a link it triggers the javascript below and the value from e.view.params.street_id is taken (for example: 2) and filters the obj's street_id field. I then want to take data from the filtered objects in the "addresses" parameter, and fill #template (below) with the data from that. Can I do that? and how?

    <script id="template" type="text/x-kendo-template">
            <span>${street_number}</span>
           <span>${notes}</span>
    </script>

    var obj = [
        {
            "street_id": "1",
            "street_name": "First St",
            "addresses": [
                {
                    "street_number": "100",
                    "notes": "Example notes..."
                },
                {
                    "street_number": "101",
                    "notes": ""
                }
            ]
        },
        {
            "street_id": "2",
            "street_name": "Second St",
            "addresses": [
                {
                    "street_number": "200",
                    "notes": ""
                },
                {
                    "street_number": "201",
                    "notes": "Test notes..."
                }
            ]
        }
    ];
     
    var template = kendo.template($('#template').html());
     
    var dataSource = new kendo.data.DataSource({
        data: obj,
        filter: {
            field: 'street_id',
            operator: 'eq',
            value: e.view.params.street_id
        },
        change: function() {
            $('#streets').html(kendo.render(template, this.view()));
        }
    });

    dataSource.read();
Back to Top