Appcelerator Studio LiveView重新编译错误

时间:2016-09-08 13:31:22

标签: titanium appcelerator titanium-alloy appcelerator-titanium

LiveView尝试重新编译时不断出现此错误。任何人都可以了解LiveView的工作原理吗?对象" Alloy.Globals.layout.activityList"存在,但也许LiveView只重新编译Alloy Globals不存在的代码部分?

[ERROR] :  Script Error {
[INFO] :   {
[ERROR] :      column = 36;
[ERROR] :      line = 28;
[ERROR] :      message = "undefined is not an object (evaluating 'Alloy.Globals.layout.activityList')";

"电影" Appcelerator中的示例应用程序使用与Alloy.js中的布局对象相同的逻辑。我做了完全相同的事情,但它在10次中有8次重新编译。

/**
 * Calculate element dimensions for given screen size
 * @param {Object} size   containing width and height properties
 */
Alloy.Globals.calculateElementDimensions = function(size) {

  var layout = {};

  layout.device = {};
  layout.device.width = size.width;
  layout.device.height = size.height;

  // lists
  layout.activityList = {};
  layout.activityList.cell = {};

  layout.activityList.cell.width = size.width;
  layout.activityList.cell.height = 60;
  layout.activityList.cell.spacing = 1;

  layout.activityList.cell.dateView = {};
  layout.activityList.cell.dateView.width = layout.activityList.cell.height;
  layout.activityList.cell.dateView.height = layout.activityList.cell.height;

  layout.activityList.cell.detailsView = {};
  layout.activityList.cell.detailsView.width = (layout.activityList.cell.width - layout.activityList.cell.dateView.width) - 50;
  layout.activityList.cell.detailsView.height = layout.activityList.cell.height;

  layout.activityList.cell.deleteView = {};
  layout.activityList.cell.deleteView.width = size.width * 0.2;
  layout.activityList.cell.deleteView.right = (0 - layout.activityList.cell.deleteView.width);
  return layout;
};

// Calculate element dimentsions
Alloy.Globals.layout = Alloy.Globals.calculateElementDimensions(Alloy.Globals.Device);
Alloy.Globals.getCalculatedWidth = function(_percentage){
  return (Alloy.Globals.Device.width * (_percentage / 100));
};

#UPDATE

我想我可能已经发现了什么触发了错误。它似乎不是运行新的更新代码的问题,而是在关闭和刷新之前出现错误。

**[INFO] :   [LiveView] Reloading App**
[INFO] :   Login win close
[INFO] :   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[INFO] :   validateLogInInfo
[INFO] :   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[INFO] :   UI SHUTDOWN COMPLETE. TRYING TO RESUME RESTART
[INFO] :   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[INFO] :   RUNNING CODE IN ACTIVITIES.JS
[INFO] :   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
**[ERROR] :  Script Error {
[ERROR] :      column = 36;
[ERROR] :      line = 42;
[ERROR] :      message = "undefined is not an object (evaluating 'Alloy.Globals.layout.device')";
[ERROR] :      stack = "Controller\ncreateController\nController\ncreateController\nvalidateLogInInfo\n";
[ERROR] :  }
Alloy.createController('login', {
    callback: validateLogInInfo
  }).getView().open();**

错误似乎与我在window.close事件处理程序中运行代码有关。例如,在一个控制器中,我这样做:

  Alloy.createController('login', {
    callback: validateLogInInfo
  }).getView().open();

在login.js中我做:

$.win.addEventListener('close', function(){
  log('Login win close');
  args.callback();
});

我想当LiveView尝试关闭并刷新时,回调就会尝试运行,因此编译错误。删除windoew.close事件中的回调会导致重新加载成功

[INFO] :   [LiveView] Reloading App
[INFO] :   Login win close
[INFO] :   UI SHUTDOWN COMPLETE. TRYING TO RESUME RESTART

那么,提供一个对其他控制器的close事件的回调完全是错误的方式来做这些事情吗?

1 个答案:

答案 0 :(得分:1)

是的,代码似乎是正确的。尝试在LiveView模式和Trace Console模式下运行应用程序,然后查看是否还有其他因素导致此问题。enter image description here

请参阅图像以设置跟踪模式。