Appcelerator问题:currentWindow:Titanium.UI.Window-自SDK 6.0.0起已从Titanium中删除

时间:2018-08-16 12:00:50

标签: javascript titanium appcelerator

根据documentationcurrentWindow已与Titanium.UI.Window.url属性一起删除,以在其自身的上下文中加载JavaScript文件。我已成功使用require()删除了URL引用。

我继承了一个引用currentWindow的项目来管理不同的页面资产,例如:

var thisWindow = Titanium.UI.currentWindow;
// var thisWindow = Ti.UI.currentWindow; - also doesn't work
var nav = Titanium.UI.iOS.createNavigationWindow({
    window: thisWindow
});

thisWindow.nav = nav;
nav.open();

var detailWindow = Ti.UI.createWindow({
    backgroundColor: '#fff',
    backButtonTitle: '',
    navTintColor: '#FFF',
    barColor: '#222222',
    getURL: 'http://google.com',
    titleControl: Ti.UI.createLabel({
         //text: 'TITLE',
         color: '#FFF',
         font: {
              fontSize: 16,
              fontWeight: 'bold'
         }
     })
  });

  detailWindow = require('details');
  // add the detail to the nav window
  detailWindow.nav = thisWindow.nav;

这是details.js的内容:

var window = Ti.UI.currentWindow;
var website = window.getURL;

var webview = Titanium.UI.createWebView({
    backgroundColor:"#fff",
    url:website
});

window.add(webview);

由于不再受支持,因此出现错误:

undefined is not an object (evaluating 'thisWindow.nav=nav')

如何更新该方法(理想情况下无需进行大量重写,因为以这种方式链接了许多页面和页面元素)。

谢谢!

1 个答案:

答案 0 :(得分:0)

您可以使用commonjs结构。

如果您需要将窗口从一个文件传递到另一个文件,请使用设置器将其提供。

// main.js
var details = require('details');
details.setWindow(myWindowVar);

// details.js
var window;
exports.setWindow = function(win){
    window = win;
}

当然,使用get aso的另一种方法。

// details.js
exports.window = window;

// main.js
detailWindow = require('details').window;

请记住,当使用require时,它将被加载到内存中。当稍后再次需要时,您遇到的是同一件事,它将不会重新生成。如果您确实需要创建它的功能,然后运行它。

//details.js
function createWindow(){
  var win = Ti.UI.createWindow();
  return win;
}