1

I'm trying to create different context menus in QML, but I don't know what is the correct syntax for that. I would like to do something like:

contextActions: [
                              ActionSet {
                                  title: "Action Set"
                                  subtitle: "This is an action set."

                                  actions: if (_corporate.currentView == 2) {
                                      [ ActionItem { title: "Action 1" },
                                      ActionItem { title: "Action 2" },
                                      ActionItem { title: "Action 3" } ]
                                      } else {
                                        [ActionItem { title: "Action 4" },
                                        ActionItem { title: "Action 5" },
                                        ActionItem { title: "Action 6" }
                                         ]
                                      }
                              } // end of ActionSet  
                       ] // end of contextActions list

That's obviously wrong syntax, so what is the correct way? Thanks in advance!

4

2 に答える 2

1

Perhaps something like this:

ActionItem { title: _corporate.currentView == 2 ? "Action 1" : "Action 4" }

Or if you have more values to check for, use a function:

    ActionItem {
     title: getTitleForView(_corporate.currentView);
     function getTitleForView(vid) {
      switch (vid) {
       case 1:
        return "abc"
       case 2:
        return "qwerty"
      }
     }
    }
于 2013-01-14T15:56:25.623 に答える
1

The correct way for me (enabling me to have different number of context menu items in different cases) is to use different elements which would be chosen from depending from the context.

In my case, I have a list in which I can have separate ListItemComponents depending on the type of the data. I wasn't too specific when asking the question, sorry.

Here's the correct answer, with code samples: http://supportforums.blackberry.com/t5/Cascades-Development/Context-dependent-contextActions/td-p/2044783

What is missing there, is the example of usage of the DataModel::itemType() function (crucial in this scenario), so here's an example of that: https://developer.blackberry.com/cascades/documentation/ui/lists/groupdatamodel.html

于 2013-01-15T00:11:28.043 に答える