{"action":"closed","issue":{"url":"https://api.github.com/repos/regularjs/regular/issues/51","labels_url":"https://api.github.com/repos/regularjs/regular/issues/51/labels{/name}","comments_url":"https://api.github.com/repos/regularjs/regular/issues/51/comments","events_url":"https://api.github.com/repos/regularjs/regular/issues/51/events","html_url":"https://github.com/regularjs/regular/issues/51","id":110790423,"number":51,"title":"嵌套组件调用外层组件的方法this没有指向外层组件","user":{"login":"zjzhome","id":7656953,"avatar_url":"https://avatars.githubusercontent.com/u/7656953?v=3","gravatar_id":"","url":"https://api.github.com/users/zjzhome","html_url":"https://github.com/zjzhome","followers_url":"https://api.github.com/users/zjzhome/followers","following_url":"https://api.github.com/users/zjzhome/following{/other_user}","gists_url":"https://api.github.com/users/zjzhome/gists{/gist_id}","starred_url":"https://api.github.com/users/zjzhome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zjzhome/subscriptions","organizations_url":"https://api.github.com/users/zjzhome/orgs","repos_url":"https://api.github.com/users/zjzhome/repos","events_url":"https://api.github.com/users/zjzhome/events{/privacy}","received_events_url":"https://api.github.com/users/zjzhome/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/regularjs/regular/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-10-10T11:52:45Z","updated_at":"2015-10-11T11:50:47Z","closed_at":"2015-10-11T11:50:47Z","body":"波神, 最近写了一个简单的ajax组件,调用方式类似这样\r\n```html\r\n<ajax url=\"data.json\" dataType=\"json\" onSuccess={this.handleData}></ajax>\r\n```\r\n直接将请求成功或者失败的方法作为属性, 但这样调用的外层组件的方法内的this不是指向外层组件的. \r\n\r\n把它放到模板内:\r\n```javascript\r\n\tvar Demo = Regular.extend({\r\n\t\ttemplate: '<div class=\"content\">{user}<ajax url=\"data.json\" dataType=\"json\" onSuccess={this.handleData}></ajax></div>',\r\n\t\tdata: {\r\n\t\t\tuser: ''\r\n\t\t},\r\n\t\thandleData: function(result) {\r\n\t\t\tvar html = 'name: ' + result.name + ', gender: ' + result.gender;\r\n\t\t\tthis.data.user = html;  //这里的this指向了window, 报错\r\n\t\t\tthis.$update();  \r\n\t\t}\r\n\t});\r\n\r\n\tvar demo = new Demo();\r\n\r\n\tdemo.$inject('#app')\r\n```\r\n\r\n"}}