[英]calling class method of another javascript in query
The error is: 错误是:
ReferenceError: $portal is not defined $portal.user = {
ReferenceError:未定义$ portal $ portal.user = {
i am writing whole new thing with Jquery and normal javascript.(this is my first web project still learning.) 我正在用Jquery和普通的javascript编写全新的东西。(这是我第一个还在学习的Web项目。)
I am trying to execute $portal.user.init() function from Jquery document ready function, it is not executing. 我正在尝试从Jquery文档就绪函数执行$ portal.user.init()函数,但未执行。
I may be missing something, could any one please help, how i should call above method from Jquery & concept behind it. 我可能会丢失一些东西,请问任何人可以帮忙,我应该如何从Jquery及其背后的概念调用上述方法。
here is my jQuery code 这是我的jQuery代码
<script type="text/javascript">
$( document ).ready(function() {
// Initiate portal..
$portal.user.init(<?php echo $_SESSION['user_id']; ?>,
"<?php echo $_SESSION['user_name']; ?>",
"<?php echo $_SESSION['acc_type']; ?>",
"<?php echo $_SESSION['lang']; ?>",
"<?php echo $_SESSION['first_name']; ?>",
"<?php echo $_SESSION['last_name']; ?>",
"<?php echo $_SESSION['picture']; ?>",
"<?php echo $_SESSION['email']; ?>"
);
});
And i created another javascript file say myweb.js code is like this 我创建了另一个JavaScript文件,说myweb.js代码是这样的
var _no_profile_pic = "../img/no_profile_pic.png";
/*
* Class : $portal.user
* Desc : Portal User Related Functions
*/
$portal.user = {
user_id: 0,
user_name: '',
acc_type: '',
lang: '',
first_name: '',
last_name: '',
picture: '',
email: '',
/*
* $portal.user.init : Initilise user
* Params :
* user_id - user id
* user_name - login user name
* acc_type - Type of user account like (A - Admin, V - Verified, U - Unverified, D - Deleted)
* lang - User Language like (en-english)
* first_name - User First Name
* last_name - User Last Name
* picture - User Picture URL
* email - User Email Address
* Returns : None
*/
init: function(user_id, user_name, acc_type, lang, first_name, last_name, picture, email)
{
$portal.user.user_id = user_id;
$portal.user.user_name = user_name;
$portal.user.acc_type = acc_type;
$portal.user.lang = lang;
$portal.user.first_name = first_name;
$portal.user.last_name = last_name;
$portal.user.picture = (picture == indef || picture == '' ? _no_profile_pic : picture);
$portal.user.email = email;
alert(this.user_id);
}
};
You must first define $portal
as an object, before you try to set its properties by adding the user object. 在尝试通过添加用户对象设置其属性之前,必须先将
$portal
定义为一个对象。
$portal = {}; // define $portal as an object
// now the user object can be added
$portal.user = {
...
...
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.