错误,如果我尝试在AppCelerator上打开新视图



我正在使用AppCelerator构建一个简单的应用程序。因此,我有索引视图,即启动应用程序后,我希望此索引视图打开登录视图。

所以我有:

login.xml

<Alloy>
    <View class="container">
        <View class="images"></View>
        <Label id="loginLable"
            class="loginLable">Accedi</Label>
        <TextField class="textLogin"></TextField>
    </View>
</Alloy>

login.js

// Arguments passed into this controller can be accessed via the `$.args` object directly or:
var args = $.args;
function loginEventListener(e){
    Ti.API.info("You clicked the button");
};

index.js

var login = Alloy.createController("login",args).getView();
login.open();

如果我尝试启动此应用程序,则有此错误:

[ERROR] :  TiExceptionHandler: (main) [19654,21610] ----- Titanium Javascript Runtime Error -----
[ERROR] :  TiExceptionHandler: (main) [0,21610] - In alloy/controllers/index.js:35,11
[ERROR] :  TiExceptionHandler: (main) [2,21612] - Message: Uncaught TypeError: Object #<View> has no method 'open'
[ERROR] :  TiExceptionHandler: (main) [1,21613] - Source:     login.open();
[ERROR] :  V8Exception: Exception occurred at alloy/controllers/index.js:35: Uncaught TypeError: Object #<View> has no method 'open'

您不能"打开"一个视图。它需要一个容器。您可以将其添加到已经打开的窗口中,或者需要将控制器作为窗口。open()不存在视图。

<Alloy>
    <Window>
    <View class="container">
        <View class="images"></View>
        <Label id="loginLable"
            class="loginLable">Accedi</Label>
        <TextField class="textLogin"></TextField>
    </View>
    </Window>
</Alloy>

然后,要打开它,您可以做与已经

相同的

最新更新