pebble.js Selecting menuItem dont work

196 views Asked by At

im trying to make a 3 - Step - menu. In the last step the user need the item information from first ui.menu(). I only get the last selected menu ItemIndex from menu3 so first select menu3=menu1 first select, and so on. Here my code:

var UI = require('ui');

var reciep = "";
var body = "";

// Make a list of menu items
var menu1 = [
    {
        title: "",
        number: "465465465"
    },
    {
        title: "",
        number: "33333"
    },
    {
        title: "",
        number: "131321321"
    }
];

// Create the Menu, supplying the list of menu1
var menuOne = new UI.Menu({
    sections: [
        {
            title: 'Empfänger',
            items: menu1
        }
    ]
});

// Show the Menu
menuOne.show();

var menu2 = [
    {
        title: "MSG",
        subtitle: ""
    },
    {
        title: "",
        subtitle: ""
    },
    {
        title: "",
        subtitle: ""
    }
];

// Create the Menu, supplying the list of menu1
var menuTwo = new UI.Menu({
    sections: [
        {
            title: 'Antwortart',
            items: menu2
        }
    ]
});



var menu3 = [
    {
        title: "Hallo",
        subtitle: "Ich!"
    },
    {
        title: "Keine Zeit",
        subtitle: "bei dir!"
    },
    {
        title: "Ja",
        subtitle: "Ja"
    },
    {
        title: "Nein",
        subtitle: "Nein"
    }
];

// Create the Menu, supplying the list of menu1
var menuTree = new UI.Menu({
    sections: [
        {
            title: 'Antwortart',
            items: menu3
        }
    ]
});

// Add a click listener for select button click
menuOne.on('select', function (event) {
    menuTree.show();
});

// Add a click listener for select button click
//menuTwo.on('select', function (event) {
//    menuTree.show();
//});

// Add a click listener for select button click
menuTree.on('select', function (event) {
      body = menu3[event.itemIndex].subtitle;
      reciep = menu1[event.sectionIndex].number;

      //console.log('Selected item #' + menu3[event.itemIndex].subtitle + ' of section #' + event.sectionIndex);
      console.log('The item is titled "' + menu3[event.itemIndex].subtitle + '"');

    // Show a card with clicked item details
    var detailCard = new UI.Card({
        title: menu3[event.itemIndex].title,
        body: menu3[event.itemIndex].subtitle
    });

    // Show the new Card
    detailCard.show();
1

There are 1 answers

0
sarfata On

You should save the index of the element that was selected in a variable that will be used later. For example:

var firstMenuSelection, secondMenuSelection;

menuOne.on('select', function(event) {
  firstMenuSelection = event.itemIndex;
  menuTree.show();
});

menuTree.on('select', function(event) {
  console.log("Selection path is " + firstMenuSelection + " - " + event.itemIndex);
});