Sugarcrm支持产品指南糖开发人员糖开发人员指南10.0用户界面路线

路线

概述

路由确定用户基于URL中的模式指导的位置。

路线

路线, defined in ./include/javascript/sugar7.js, are URL patterns signified by a hashtag ("#") in the URL. An example module URL pattern for the Sugar application is http://{site url}/#<module>. This route would direct a user to the list view for a given module. The following sections will outline routes and how they are defined.

路线定义

路由器以以下格式接受路由定义:

路线 = [
    {
        name: "My First Route",
        route: "pattern/to/match",
        callback: function()
        {
            //handling logic here.
        }
    },
    {
        name: "My Second Route",
        route: "pattern/:variable",
        callback: "<callback name>"
    }
]

路由占三个属性:路由的名称,要匹配的路由模式,以及在路由匹配时要调用的回调。如果需要默认回调,则可以将呼叫名称指定为字符串。

路线模式

路由模式确定指导用户的位置。导航到帐户记录时,将完成路由的示例。执行此操作时,您可能会注意到您的URL是:

http://{site url}/#Accounts/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee

A stock route's definition is defined in ./include/javascript/sugar7.js as:

{
    name: "record",
    route: ":module/:id"
},

Variables in the route pattern are prefixed with a colon such as :variable. The route pattern above contains two variables:

  • 模块
  • ID

自定义路线

As of 7.8.x, you can add the routes during the initialization of the Router, so custom routes can be registered in the Sidecar router during both 路线r:init and 路线r:start events. It is recommended to register them in the Initialization event before any routing has occurred. There are two methods in the Sidecar Router, which allow for adding custom routes:

路线()

争论

名称 必需的 类型 描述
路线 真的 细绳 由URL片段匹配的路由模式
名称 真的 细绳  路线的唯一名称
打回来 真的 功能  路线的回调函数

例子

The following example registers a custom Route during the 路线r:init event, using the 路线() method.

./custom/javascript/customroutes.js.

(function(app){
    app.events.on("路线r:init", function(){
      //Register the route #test/123
      app.router.route("test/:id", "test123", function() {
          console.log(arguments);
          app.controller.loadView({
              layout: "custom_layout",
              create: true
          });
      });
    })
})(SUGAR.App);

addroutes()

When you need to add multiple routes, you can define the routes in an array and pass the entire array to the addroutes() method on the Sidecar Router to ensure they are registered. Please note, the addroutes() method utilizes the above 路线() method to register the routes with the Backbone Router. The Backbone router redirects after the first matching route. Due to this, the order in which the routes are listed in the array is important as it will determine which route will be used by the application. It is recommended that the most specific routes be listed first in the array so that they are recognized first, instead of those routes which may contain a variable.

争论

名称 必需的 类型 描述
路线 真的 大批 如上定义的路由定义数组。

例子

The following example registers custom Route during the 路线r:init event, using the addroutes() method.

The route's JavaScript controller can exist anywhere you'd like. For our purposes, we created it in ./custom/javascript/customroutes.js.. This file will contain your custom route definitions.

./custom/javascript/customroutes.js.

(function(app){
    app.events.on("路线r:init", function(){
        var routes = [
    	    {
                route: 'test/doSomething',
                name: 'testDoSomething',
                callback: function(){
             	    alert("Doing something...");
                }
            },
            {
                route: 'test/:id',
                name: 'test123',
                callback: function(){
             	    console.log(arguments);
                    app.controller.loadView({
                        layout: "custom_layout",
                        create: true
                    });
                }
            }
        ];
        app.router.addRoutes(routes);
    })
})(SUGAR.App);

接下来,创建JSGrouping扩展名。此文件将允许Sugar识别您添加了自定义路由。 

./custom/extension/pplication/ext/jsgroupings/mycustomroutes.php.

<?php

foreach ($js_groupings as $key => $groupings) {
    $target = current(大批_values($groupings));

    //if the target grouping is found
    if ($target == 'include/javascript/sugar_grp7.min.js') {
        //append the custom JavaScript file
        $js_groupings[$key]['custom/javascript/customRoutes.js'] = 'include/javascript/sugar_grp7.min.js';
    }
}

文件到位后,导航到Admin> Repairs > Quick Repair &重建。有关其他信息,请参阅 JSGroupings. framework.

最后修改:2020-03-16 17:00:15