Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ViewModel中vm作用域bug #6

Closed
wghy2004 opened this issue Jun 15, 2013 · 4 comments
Closed

ViewModel中vm作用域bug #6

wghy2004 opened this issue Jun 15, 2013 · 4 comments

Comments

@wghy2004
Copy link

描述可能不准确,具体看代码
html 代码:

<form ms-controller="login">        
  <input type="text" ms-model="user" ms-on-blur="validate.user"/>      
</form>

js 代码:

 var login=avalon.define('login',function(vm){
            vm.user='';
            vm.validate={
                user:function(){
                    avalon.log(vm.user);//取不到值
                    avalon.log(login.user);//正常
                }                
            }  
 })
@RubyLouvre
Copy link
Owner

其实是这样的,vm只是用来定义的,它与define 返回的对象不是同一个对象。而对视图进行绑定时,我们是用返回的login对象。

@wghy2004
Copy link
Author

avalon.log(vm.user);//取不到值
avalon.log(login.user);//正常

我只能用login.user?

@RubyLouvre
Copy link
Owner

是的,你这个是一个事件回调,this是指向绑定事件的元素节点;而它里面想指向viewModel,只能用avalon.define的返回值

@RubyLouvre
Copy link
Owner

我暂时还没有什么好办法来hack这个vm

RubyLouvre pushed a commit that referenced this issue Feb 13, 2014
Merge pull request #5 from RubyLouvre/master
RubyLouvre pushed a commit that referenced this issue Feb 6, 2015
RubyLouvre pushed a commit that referenced this issue Jul 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants