移动safari上的流星模板不会显示我的回报

时间:2013-02-21 21:04:38

标签: javascript mobile-safari meteor

我正试图在我的模板功能返回的移动safari屏幕上显示。 我可以看到我的设备支持devicemotion 我可以看到我的var tiltFB的控制台日志和数据

我无法看到或开始工作的是它在我的移动野生动物园的html屏幕上显示。

Template.tapapp.showAngle = function() {

var tiltFB;

if (window.DeviceMotionEvent) {
  window.addEventListener('devicemotion', deviceMotionHandler, false);
  console.log("Devicemotion IS supported on your device.");
} else {

  console.log("Devicemotion Not supported on your device.");
  return "Devicemotion Not supported on your device.";
}

function deviceMotionHandler(eventData) {

  var acceleration = eventData.accelerationIncludingGravity;
  var rawAcceleration = "[" +  Math.round(acceleration.x) + ", " +     Math.round(acceleration.y) + ", " + Math.round(acceleration.z) + "]";

  var facingUp = -1;
  if (acceleration.z > 0) {
    facingUp = +1;
  }

  tiltFB = Math.round(((acceleration.y + 9.81) / 9.81) * 90 * facingUp);

  console.log(tiltFB);

  //Meteor.defer(function () {
  //     $('#angel').html(tiltFB);
  //     return tiltFB;
  });
  return tiltFB;
}

};

这是我的HTML:

<template name="tapapp">
  <div class="container">
  <h3 class="angel-class" id="angle">{{showAngle}}</h3>
</template>

1 个答案:

答案 0 :(得分:1)

试试这个,你需要在你的showAngle助手中返回一个值,并通过Session.set / get

反复挂钩

客户js

function deviceMotionHandler(eventData) {

  var acceleration = eventData.accelerationIncludingGravity;
  var rawAcceleration = "[" +  Math.round(acceleration.x) + ", " +     Math.round(acceleration.y) + ", " + Math.round(acceleration.z) + "]";

  var facingUp = -1;
  if (acceleration.z > 0) {
    facingUp = +1;
  }

  tiltFB = Math.round(((acceleration.y + 9.81) / 9.81) * 90 * facingUp);

  console.log(tiltFB);

  //Meteor.defer(function () {
  //     $('#angel').html(tiltFB);
  //     return tiltFB;
  //});
  Session.set("tiltFB", tiltFB);
}


Template.tapapp.showAngle = function() {
    return Session.get("tiltFB");
}

Meteor.startup(function() {
    if (window.DeviceMotionEvent) {
        window.addEventListener('devicemotion', deviceMotionHandler, false);
        console.log("Devicemotion IS supported on your device.");
    } else {
        console.log("Devicemotion Not supported on your device.");
    }
});