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

Passing Route Parameters to a View

1 Answer 249 Views
SPA
This is a migrated thread and some comments may be shown as answers.
Brendan
Top achievements
Rank 1
Brendan asked on 30 Dec 2014, 04:09 AM
I'm starting a new project and would like to use Kendo's SPA along with RequireJS for the design; however, I'm running into a roadblock that I just can't get by and I'm hoping someone here has dealt with it in the past.  My issue comes down to passing route parameters to a view for rendering.  My current sample code is as follows:

main.js
(function () {
    require.config({
        deps: ["js/jquery"]
    });
     
    require(['app'], function(App){
 
        App.start();
    });
})();

app.js
define([
  'kendo/js/kendo.all.min',
  'controllers/ListController'
], function (kendo, list) {
 
    var router = new kendo.Router({
        routeMissing: function (e) {
            console.log('No Route Found', e.url);
        }
    });
     
    router.route("list/(:id)", function(id) {
        var myIdParameter = id;
 
        // TODO Find a way to pass the myIdParameter to the view I'm about to render.
 
        // Render the view in the "app" div
        list.render("#app");
    });
 
    return router;
 
});

ListController.js
define(['kendo/js/kendo.all.min'], function (kendo) {
     
    // TODO I would like to have the "1234" value passed from the route parameter
    var viewModel = kendo.observable({
        id: "1234"
    });
 
    var options = {
        model: viewModel
    };
     
    return new kendo.View(
        "index",
        options
    );
});

My goal is to use the ListController for the various js logic for creating various kendo widgets for the view I'm trying to render; however, If I can't find a good way to pass parameters along to use with my future datasource calls I going to be stuck.  Any push in the right direction here would be greatly appreciated.

Thanks,
-Brendan

1 Answer, 1 is accepted

Sort by
-1
Accepted
Petyo
Telerik team
answered on 30 Dec 2014, 12:37 PM
Hello Brendan,

the SPA view itself does not have the concept of parameters. What you may do in that case is to actually set the state of the view model instance, thus configuring the view options. 

Regards,
Petyo
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
SPA
Asked by
Brendan
Top achievements
Rank 1
Answers by
Petyo
Telerik team
Share this question
or