Hi all,
I've been trying for hours to dynamically populate a kendo sub-menu with processed database items, and have those menu items call a javascript function on click. I've read all over the internet that with jQuery, I should really be using event listeners, but that's really difficult when the kendo menu populates its menus with identical IDs and classes on all its items, and I'd have to dynamically create different numbers of event listeners based on the quantity of items in the menu, and I don't even know if that's possible. Therefore, I'm trying to populate the menu with custom div elements with ng-click data to call a function. My javascript file is separate from the HTML file, but I know they're connected properly because other places on the page interact with the javascript functions just fine. When I use ng-click in the inner div I'm inserting via json, absolutely nothing happens. The breakpoint in the called function is never hit, but I know the function works because I created a simple test element elsewhere on the page using the exact same ng-click logic, and it called and executed the function just fine. We're using transformative kendo rather than the raw HTML tags. Here's a code snippet:
//Transform the kendo menu
$("#kendoMenu").kendoMenu();
//other code populating $scope.listOfMilestone from the database, we know that works because the vis timeline generates correctly
var milestonesReadable = new Array();
for (var i = 0; i < $scope.listOfMilestones.length; i++) {
var milestoneDate = new Date($scope.listOfMilestones[i].StartDate);
var dateString = (milestoneDate.getMonth() + 1) + "/" + milestoneDate.getDate() + "/" + milestoneDate.getFullYear();
milestonesReadable.push({
text: "<div ng-click=\"navigate('" + dateString + "')\">" + $scope.listOfMilestones[i].Title + " (" + dateString + ")</div>",
encoded: false
});
}
$("#dropdownMilestoneList").kendoMenu({
dataSource: milestonesReadable
});
//way further down in the javascript:
$scope.navigate = function (dateString) {
debugger;
$scope.timeline.moveTo(dateString);
}
Here's the essential structure of our <ul> structure that the kendo menu uses:
<ul id="kendoMenu>
<li>
Customize Timeline
<ul>
<!--many layers of menu that we know all work correctly-->
<li>
Functions
<ul>
<li>
Go to Milestone
<ul id="dropdownMilestoneList></ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
When that innermost ul tag is populated (which appears correctly with appropriate data), and is checked using inspect element, you can see inside each <span class="k-link"> tag that indicates a menu item, there is indeed a div element with correct ng-click data, exactly as it was in my test element that worked. However, when you click on any of these menu items, the ng-click just doesn't do anything. No function call, no error, just nothing. When I replace it with the base HTML's onclick, an error is thrown, though:
Uncaught ReferenceError: navigate is not defined
at HTMLDivElement.onclick
I'm at a total loss. Any advice would be appreciated.
Thanks.