【问题标题】:containingTab cause on undefined is not an object未定义的 containsTab 原因不是对象
【发布时间】:2014-04-26 20:22:19
【问题描述】:

在我的基于钛的应用程序中,我的导航流程如下所示

HomeVu -> Subvu1 -> Subvu2

当我试图从 Subvu1 视图导航到 Subvu2 时,它显示一个错误,

  Script Error 
  {
  backtrace = "#0 () at :0";
  line = 40;
  message = "'undefined' is not an object (evaluating 'ReportSubWindow.containingTab.open')";
  name = TypeError;
  sourceId = 300153536;
  sourceURL = "file:///Users/administrator/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/9A6B5752-F198-48AC-9E23-2A0DC31A2BD2/test.app/SubVu/text.js";
  } 

这里是代码

HomeVu

  button2.addEventListener('click', function() 
  {
    var FindAnExpertSubWindow = require('SubVu/email');
    self.containingTab.open(new FindAnExpertSubWindow('My Mail'));
  });

Subvu1

function FindAnExpertSubWindow(title) 
{
var findAnExpertSubWin = Ti.UI.createWindow({
    backgroundColor : 'white', });
var button1 = Ti.UI.createButton({
    backgroundImage: 'ui/images/Untitled.png',
    height:32,
    width:87,
    top:90,
    left:115,

});

button1.addEventListener('click', function() 
{
var FindAnExpertSubWindow = require('SubVu/email');
    findAnExpertSubWin.containingTab.open(new FindAnExpertSubWindow('My Mail'));
});
findAnExpertSubWin.add(button1);
return findAnExpertSubWin;
    };
 module.exports = FindAnExpertSubWindow; 

Subvu2

 function ReportSubWindow(title) 
 {
var reportSubWin = Ti.UI.createWindow({
backgroundColor : 'black',
    });
 return reportSubWin;
 };
 module.exports = ReportSubWindow; 

如何从 Subvu1 导航到 Subvu2?

【问题讨论】:

    标签: titanium titanium-modules createwindow


    【解决方案1】:

    当您创建 Subvu1 窗口时,您必须像在 HomeVu 窗口中一样设置 containsTab 属性。您的代码示例缺少那部分代码,但可能看起来像这样:

    HomeVu

    button2.addEventListener('click', function() {
        var FindAnExpertSubWindow = require('SubVu/email');
        self.containingTab.open(new FindAnExpertSubWindow('My Mail', self.containingTab));
    });
    

    Subvu1

    function FindAnExpertSubWindow(title, containingTab) {
        var findAnExpertSubWin = Ti.UI.createWindow({
            backgroundColor : 'white',
            containingTab: containingTab,
        });
        /* ... */
    });
    

    另一种解决方法是停止在每个窗口之间传递对 Tab 对象的引用,只创建一个全局对象,您将使用它来打开新窗口。

    如果没有帮助,请发布更多示例代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-11
      • 2021-01-26
      相关资源
      最近更新 更多