小编BIO*_*IOS的帖子

在JQuery方法中设置匿名函数的'this'上下文

我想通过以下单击绑定方法传递特定上下文:

$(document).ready(function(){

    var o = {
        name : 'I\'m object O'
    };

    $('#my-button').click(function(){
        alert(this.name);
    }.call(o));
});
Run Code Online (Sandbox Code Playgroud)

问题是,只要页面加载就会触发此操作.有没有办法可以将上下文绑定到click处理程序的匿名函数,并且只有在触发click事件时才触发它?你也可以解释为什么它是在页面加载而不是点击事件上触发的.

javascript jquery this javascript-events

1
推荐指数
1
解决办法
123
查看次数

身份验证登录时出现致命错误

我在尝试登录用户时收到以下错误:

Call to a member function login() on a non-object
Run Code Online (Sandbox Code Playgroud)

我的登录操作使用外部模型.行动是:

public function login() {

        $this->loadModel('User');

        if ($this->request->is('post')) {

           $theUser = $this->User->find('first', array('conditions' => array('User.username' => $this->request->data['User']['username'])));    

            if($theUser['User']['activated'] == TRUE){

                if ($this->Auth->login($this->request->data)){

                   $this->Session->setFlash('Logged in successfully');

                    $this->redirect(array('controller' => 'admin', 'action' => 'index'));
                } else {

                    $this->Session->setFlash('Username or password is incorrect');
                }
            }else $this->Session->setFlash('User not yet activated. Please Contact administrator.');
        }
    }
Run Code Online (Sandbox Code Playgroud)

传递给的请求数据$this->Auth->login是:

array(
    'User' => array(
        'password' => '*****',
        'username' => 'admin'
    )
)
Run Code Online (Sandbox Code Playgroud)

$this->Auth->login($this->request->data) 是导致致命错误的行.

有人可以解释错误的确切含义以及可能导致错误的原因吗?

authentication cakephp cakephp-model

1
推荐指数
1
解决办法
336
查看次数

wordpress中的Php条件

有人可以向我解释一下在查看word press中的php用法时经常遇到的替代语法的使用.以条件为例:

我希望看到:

if(10==10)
echo 'this is true and will be shown';
Run Code Online (Sandbox Code Playgroud)

相反,我看到:

if(10==10):
echo 'this is true and will be shown;
end if;
Run Code Online (Sandbox Code Playgroud)

另一个例子:

! empty ( $classes_names ) 
and  $class_names = ' class="'. esc_attr( $class_names ) . '"';
Run Code Online (Sandbox Code Playgroud)

什么是':''结束如果;' 并且最后一个示例语法不是我之前看到的那样的东西.

php wordpress conditional

0
推荐指数
1
解决办法
62
查看次数

对于in循环,返回字符串而不是对象

我有包含嵌套对象的javascript对象.我想使用'for in'循环迭代这些但是这会返回一个字符串而不是一个对象?

码:

var myObject = {


    myNestedObject : {

        key1 : value 1 

    }

}
Run Code Online (Sandbox Code Playgroud)

然后,如果我循环:

for(theObject in myObject){

    alert(typeof theObject);

}
Run Code Online (Sandbox Code Playgroud)

这将返回字符串'myNestedObject',但不返回对象本身.

为什么?

javascript

0
推荐指数
1
解决办法
110
查看次数