pebble.js选择menuItem不起作用

时间:2015-08-13 20:27:47

标签: pebble-watch pebble-js

我试图制作一个三步菜单。在最后一步中,用户需要来自第一个ui.menu()的项目信息。我只从menu3获取最后选择的菜单ItemIndex,因此首先选择menu3 = menu1首先选择,依此类推。这是我的代码:

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 个答案:

答案 0 :(得分:0)

您应该保存在稍后将使用的变量中选择的元素的索引。例如:

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);
});