Closed lo-co closed 8 years ago
https://github.com/Templarian/ui.bootstrap.contextMenu#menu-options The first code example shows the signature.
Basically it's an array that is overloaded to allow either a string
or function
as some people need dynamically named items depending on what they are right clicking.
function ($itemScope, $event, model) {
return $itemScope.item.name;
}
Note: as shown in the example model
is an optional attribute if you need to easily pass in an additional object.
Sorry forgot to answer the second part of the question. The 2nd line of code is for enable/disabling of the context menu items. Very useful when right clicking items from a list where some have different actions.
Please look at the example codepen in the readme. It demos these abilities.
OK. Thanks Austin. Now for a question born out of my ignorance - why does the example function signature not resemble the called function signature?
So, in JavaScript the first parameter is actually the function scope or this
.
function foo(p1) {
// this.bar == 'hello world!'
// p1 == 'cool right'
}
foo.call({bar: 'hello world!'}, 'cool right')
Oh wait, I think you found a bug... that 2nd param should be...
item[2].call($scope, $scope, event, model, text)
Hmm... that needs to be fixed.
Perfect...thanks.
Okay, I've fixed this in v0.9.5
, but I'm not going to document it since I'm not sure exactly the purpose of passing in the text would be. It also gets confusing since model
is optional.
v0.9.6
is out now also. Closing this issue.
Just a question, but I don't see labels showing up here. You have the following code where you expect a string for the text in the first argument but account for a function if the type is not a
string
(line 25):What is the intention of the function for
item[0]
(I assume to return a string) and what is this signature?You have a similar definition below this (line 30):
It seems to have the same signature as the function call above. What is the intention of this line?