Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

call function model from controller

$
0
0

I am wrote this code in a model (user):

extendModel: function(Model) { _.extend(Model.prototype, { loginUser: function(username, password) { // Dummy authentication. In a real world scenario, this is // where you'd make a request to your authentication server or // other form of authentication. It would also likely return // the server time for loggedInSince, rather than using client-side // time like we are here. if (username === USERNAME && password === PASSWORD) {

                return true;
            } else {
                return false;
            }
        }
    });

    return Model;
},

and I call it from a controlle (login)r:

var user=Alloy.Models.user;

function login() { Ti.API.info($.username.value); //this value is OK Ti.API.info($.password.value); //this value is OK if (user.loginUser($.username.value,$.password.value)) { Alloy.createController('home').getView().open(); $.login.close(); } else { alert('login failed'); } }

the view is this:

<Alloy> <Window class="container" layout="vertical">
<TextField id="username" /> <TextField id="password" /> <Button id="loginButton" onClick="login">Login</Button> </Window> </Alloy>

my problem is when I click the button LOGIN show the error:

"CANNOT CALL METHOD loginUser OF UNDEFINED"

so How can I call a method in the model from controller???

thanks !!


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>