0

我正在尝试制作一个 3 步菜单。在最后一步中,用户需要来自第一个 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();
4

1 回答 1

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);
});
于 2015-08-19T19:07:42.383 回答