DevExtreme和Angular - 菜单小工具

时间:2015-08-06 17:38:50

标签: javascript angularjs widget devexpress devextreme

要在itemClick事件触发时导航到特定URL,请将该URL或该URL的锚点部分(#)直接指定为此选项作为字符串。 怎么做? 如何在单击窗口小部件项时分配一个函数来执行自定义操作? 你能举一些例子吗?

//Define directives to the Angular Route and DevExtreme
var myApp = angular.module('myApp', ['ngRoute', 'dx']);
//URL to show ?
//var serviceHome =  "http://localhost:8000/home";





//myApp.controller('appCtrl', function($scope, $http, $templateCache) {
//
//
//      
// });







// create the controller and inject Angular's $scope
myApp.controller('mainController', function($scope) {
    // create a message to display in our view
    $scope.message = 'Home';


    $scope.menuItems = [
        {
            text: "Home",
            selectable: true,
            items: [
                { text: "Home", url: "#/"},
                { text: "UI Widgets"},
                { text: 'Data Visualization'},
                { text: "Data Layer"}
            ]
        },
        {
            text: "About",
            items: [
                { text: "About", url: "#about" },
                { text: "UI Widgets", beginGroup: true },
                { text: "Data Visualization", selected: true },
                { text: "Themes" },
                { text: "Common" }
            ]
        },
        {
            text: "Contact",
            items: [
                { text: 'Contact us', url: "#contact" },
                { text: 'UI Widgets' },
                { text: 'Data Visualization Widgets', visible: true, selectable: true },
                { text: 'CSS Classes' },
                { text: 'UI Events' },
                { text: 'item1',
                    items: [
                        { text: 'First', disabled: true},
                        { text: 'Second'}
                    ]},
                { text: 'item2' },
                { text: 'item3' }               
            ]

        }
    ];         

    $scope.itemClicked = function (data) {
                    DevExpress.ui.       urlFor(data.itemData.url);
//        DevExpress.ui.notify("The \"" + data.itemData.text + "\" item is     clicked", "success", 1500);
//        DevExpress.ui.redirectTo(data.itemData.url);
    };


});

myApp.controller('aboutController', function($scope) {
    $scope.message = 'About';
});

myApp.controller('contactController', function($scope) {
    $scope.message = 'Contact us! Dr. ';
}); 





//Exposes the current URL in the browser address bar
//Maintains synchronization between itself and the browser's URL
//Represents the URL object as a set of methods
myApp.config(function($routeProvider) {
$routeProvider



// route for the home page
.when('/', {
        templateUrl : 'pages/home.html',
        controller  : 'mainController'
})

// route for the about page
.when('/about', {
        templateUrl : 'pages/about.html',
        controller  : 'aboutController'
})

// route for the contact page
.when('/contact', {
        templateUrl : 'pages/contact.html',
        controller  : 'contactController'
});    


//  $locationProvider.html5Mode(true);
});

谢谢

1 个答案:

答案 0 :(得分:1)

在您的情况下,要导航到某个网址,您可以使用http://jira.sonarsource.com/browse/SONARMSBRU-125服务。例如:

HTML:

<div ng-controller="myCtrl">
    <div dx-menu="{ items: menuItems, onItemClick: itemClicked  }"></div>
</div>

JavaScript的:

var myApp = angular.module("myApp", ["dx"]);

myApp.controller("myCtrl", function($scope, $location) {
    $scope.menuItems = [
    {
        text: "Tutorials",
        url: "/url1",
        items: [
            { text: "VS Integration", url: "/url2" }
        ]
    },
    {
        text: "Guides",
        url: "/url3",
        items: [
            { text: "Demos Inside", url: "/url4" },
            { text: "UI Widgets", url: "/url5" }
        ]
    }
    ];

    $scope.itemClicked = function(data){
        $location.path(data.itemData.url);
    };
});