1

私は Titanium を初めて使用し、問題に直面しています。私のapp.jsには、左のメニューとコントロールをウィンドウに含めています(app.jsとleftmenu.js)

ユーザーがメニュー項目をクリックしたときにウィンドウをロードしたい。非常に基本的には、ユーザーがホームページ ボタンを選択したときに app.js メイン ウィンドウをロードしたいと考えています。このために、次のコードを leftmenu.js ファイルに追加しました。

var newWin = Titanium.UI.createWindow({
    url: "app.js",
    zIndex: 0
});
win.close(); // closing main window
leftMenu.close(); // closing left menu
newWin.open(); //should reload the main window and the leftmenu

ウィンドウをリロードしますが、すべてのコントロールが無効になります。コントロールをクリックすることはできません。すべてのコントロールが非表示レイヤーの下にあるのと同じです。何か案が ?

コード部分をコピーして貼り付けます。おそらくもっと明確になります:)

btnaccueil.addEventListener('click',function(e) {
   var newWin = Titanium.UI.createWindow({        
       url: "app.js",
       zIndex: 0
   });

   // Closing current instance for freeing memory
   win.close();
   leftMenu.close();
   newWin.open({animated:true});
   Ti.API.info(var_dump(newWin));
});
4

1 に答える 1

0

こんにちは、1 か月後のことですが、require と exports/module.exports を使用していますか? これは、ボタンイベントで新しいウィンドウを開く適切な方法の例です.urlプロパティの使用は推奨されていないと思いますので、この例が理解に役立つことを願っています.

従業員.js

//Current window (employee window)
var employeeWin = Ti.UI.currentWindow;

//define button
var moveToDetailBtn = Ti.UI.createButton({
   width      : 200,      //define the width of button
   height      : 50,      //define height of the button
   title         : 'Show Detail'   //Define the text on button
});

//Click event to open the Employee Details window
moveToDetailBtn.addEventListener('click', function(){

   //Call a export function
   var win = require('employeeDetails').getEmployeeDetailSWin;

   //Create new instance
   var employeeDetailsWin = new win();

   //Open the Employee Details window
   employeeDetailsWin.open();
});

//Add the button to the window
employeeWin.add(moveToDetailBtn);

employeeDetails.js 内

exports.getEmployeeDetailSWin = function(){

   //Creates a new window
   var empDetailsWin = Ti.UI.createWindow({
      backgroundColor   : '#ffffff'      //Define the backgroundcolor of the window
   });

   //Addin a label to the window
   empDetailsWin.add(Ti.UI.createLabel({
      width      : 100,      //Define width of the label
      height      : 50,      //Define height of the label
      title         : 'Employee Details'
   }));

   return empDetailsWin;
};

さらに、app.js をエクスポートできるかどうかもわかりません。新しい .js を使用してみてください。

于 2013-02-13T18:45:13.190 に答える