Kendo template send data

What I want is simple but I don't know if it's possible.

I have a Kendo Mobile ListView as below:

e.view.element.find("#list-serviceorders").kendoMobileListView({
    dataSource: ds,
    pullToRefresh: true,
    template: $("#list-serviceorders-template").html()
});

And I want to send to the template some values to access on it. My view with the template is this:

<div data-role="view" data-before-show="GAPCP.viewBeforeShow" id="serviceorders" data-layout="main-item-list">
    <ul id="list-serviceorders"></ul>
</div>

<script id="list-serviceorders-template" type="text/x-kendo-template" data-teste="teste">
    <a href="views/entries.html?id=#: CodOs #">OS: #: CodOs #<br />
    #: parameter.Divi1 #: #: CodDivi1 #/#: parameter.Divi2 #: #: CodDivi2 #</a>
</script>

Where you can read parameter.Divi1 and parameter.Divi2 are the places where I want to display those values. They're are not in the Data Source like the others values.

I don't want to create global variable 'cause I don't want to mess with my code and I can't use a function for that purpose because those values come from the database and it will execute a query for each list item iteration.

Any suggestion of how do that?

Answers:

Answer

What I'm proposing is adding this information to the model in the controller. You can do it in DataSource.schema.parse or in requestEnd, even in a dataBound event if the widget accepts it.

When the data is received you iterate through the model and fills the remaining data not received from the server.

Example: Using parse

var ds = new kendo.data.DataSource({
    transport: {
        read: {
            url : ...
        }
    },
    schema   : {
        model: {
            CodOs   : { type: "number" },
            CodDivi1: { type: "string" },
            CodDivi2: { type: "string" }
        },
        parse: function (data) {
            $.each(data, function (idx, elem) {
                // Extend original elem
                elem.parameter = {
                    Divi1: elem.CodDivi1.toUpperCase(),
                    Divi2: elem.CodDivi2.toLowerCase()
                }
            });
            return data;
        }
    }
});

Where I compute parameter inside the parse function and set parameter.Divi1 to CodDivi1 in upper-case and parameter.Divi2 to CodDivi2 in lowercase.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.