0

現在、pebble.js (sdk 2.0) をいじっています。JSON ソースからデータをロードするメニュー ベースのアプリを作成しようとしています。

メニュー部分への入力を除いて、すべて正常に動作します。これが私のコードです:

    var UI = require('ui');
var ajax = require('ajax');
var dataJSON = [];

var fruits = [
  {
    title: "Apple",
    subtitle: "Green and crispy!"
  },
  {
    title: "Orange",
    subtitle: "Peel first!"
  },
  {
    title: "Melon",
    subtitle: "Only three left!"
  }
];

var parseFeed = function(data, quantity) {
  var items = [];
  for(var i = 0; i < quantity; i++) {
    var teamOne = data.matches[i].team1.team_tag;
    var teamTwo = data.matches[i].team2.team_tag;
    var startTime = data.matches[i].starttime;
    var title = (teamOne + ' vs ' + teamTwo);
    var time =  (startTime.substring(11) + " CET" );
    items.push({
      title:title,
      subtitle:time
    });
  }
  return items;
};

var matchMenu = new UI.Menu({
  sections: [{
    title: 'D2MT',
    items: dataJSON
  }]
});



ajax({
    url:'http://dailydota2.com/match-api',
    type:'json'
  },
  function(data) {
    dataJSON = parseFeed(data, data.matches.length);

    for(var i = 0; i < fruits.length; i++) {
      console.log('title = ' + fruits[i].title);
      console.log('subtitle = ' + fruits[i].subtitle);
    }
    for(var j = 0; j < dataJSON.length; j++) {
      console.log('title = ' + dataJSON[j].title);
      console.log('subtitle = ' + dataJSON[j].subtitle);
    }
    console.log('SHOW MENU');
    matchMenu.show();
  },
  function(error) {
    console.log('Download failed: ' + error);
  }
);

出力:

[PHONE] pebble-app.js:?: title = Apple
[PHONE] pebble-app.js:?: subtitle = Green and crispy!
[PHONE] pebble-app.js:?: title = Orange
[PHONE] pebble-app.js:?: subtitle = Peel first!
[PHONE] pebble-app.js:?: title = Melon
[PHONE] pebble-app.js:?: subtitle = Only three left!
[PHONE] pebble-app.js:?: title = Rave vs 5eva
[PHONE] pebble-app.js:?: subtitle = 14:00:00 CET
[PHONE] pebble-app.js:?: title = Arcanys vs XctN
[PHONE] pebble-app.js:?: subtitle = 14:30:00 CET
[PHONE] pebble-app.js:?: title = VP vs Meepwn'd
[PHONE] pebble-app.js:?: subtitle = 17:00:00 CET
[PHONE] pebble-app.js:?: title = Vega vs NiP
[PHONE] pebble-app.js:?: subtitle = 17:00:00 CET
[PHONE] pebble-app.js:?: title = Secret vs Empire
[PHONE] pebble-app.js:?: subtitle = 20:00:00 CET
[PHONE] pebble-app.js:?: title = SumsRift vs HR
[PHONE] pebble-app.js:?: subtitle = 20:00:00 CET
[PHONE] pebble-app.js:?: title = NiP vs Vega
[PHONE] pebble-app.js:?: subtitle = 20:30:00 CET
[PHONE] pebble-app.js:?: title = Fire vs Thu
[PHONE] pebble-app.js:?: subtitle = 23:00:00 CET
[PHONE] pebble-app.js:?: title = Signature vs G Guard
[PHONE] pebble-app.js:?: subtitle = 08:00:00 CET
[PHONE] pebble-app.js:?: title = Aces vs MVP
[PHONE] pebble-app.js:?: subtitle = 11:00:00 CET
[PHONE] pebble-app.js:?: SHOW MENU
[PHONE] pebble-app.js:?: (+) [menu 1] : [menu 1]

メニューは「Fruits」を正常にロードしますが、「dataJSON」をロードすると何もしません。データがメニューにロードされない理由を他の誰かが知っています

4

2 に答える 2