{"action":"created","issue":{"url":"https://api.github.com/repos/Tencent/wepy/issues/1025","repository_url":"https://api.github.com/repos/Tencent/wepy","labels_url":"https://api.github.com/repos/Tencent/wepy/issues/1025/labels{/name}","comments_url":"https://api.github.com/repos/Tencent/wepy/issues/1025/comments","events_url":"https://api.github.com/repos/Tencent/wepy/issues/1025/events","html_url":"https://github.com/Tencent/wepy/issues/1025","id":301976655,"number":1025,"title":"使用repeat循环渲染自定义组件时，无法实现数据的双向绑定","user":{"login":"GeniusFunny","id":24862719,"avatar_url":"https://avatars0.githubusercontent.com/u/24862719?v=4","gravatar_id":"","url":"https://api.github.com/users/GeniusFunny","html_url":"https://github.com/GeniusFunny","followers_url":"https://api.github.com/users/GeniusFunny/followers","following_url":"https://api.github.com/users/GeniusFunny/following{/other_user}","gists_url":"https://api.github.com/users/GeniusFunny/gists{/gist_id}","starred_url":"https://api.github.com/users/GeniusFunny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GeniusFunny/subscriptions","organizations_url":"https://api.github.com/users/GeniusFunny/orgs","repos_url":"https://api.github.com/users/GeniusFunny/repos","events_url":"https://api.github.com/users/GeniusFunny/events{/privacy}","received_events_url":"https://api.github.com/users/GeniusFunny/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-03-03T07:29:09Z","updated_at":"2018-03-05T02:10:27Z","closed_at":null,"author_association":"NONE","body":"wepy 1.X版本，使用repeat对自定义组件进行循环渲染时，无法将父组件的data双向绑定到子组件上，即repeat不支持props，computed，key值等等,在控制台打印为undefined；而原生小程序的wx:for只支持原生组件。\r\n解决方案是： 使用repeat将父组件的data动态绑定（:sync.item）到子组件上，在子组件上添加一个事件发射器(this.$emit()),最后在父组件添加对应的events，从而达到数据的'伪'双向绑定。即修改数据的具体代码放在父组件上，而子组件拥有是否修改数据的控制权。\r\n注：若无法为子组件绑定key值，可以为子组件绑定id，从而解决事件发射器的参数问题）\r\n肯定有更好的方法，大家一起分享分享"},"comment":{"url":"https://api.github.com/repos/Tencent/wepy/issues/comments/370290252","html_url":"https://github.com/Tencent/wepy/issues/1025#issuecomment-370290252","issue_url":"https://api.github.com/repos/Tencent/wepy/issues/1025","id":370290252,"user":{"login":"Gcaufy","id":2182004,"avatar_url":"https://avatars1.githubusercontent.com/u/2182004?v=4","gravatar_id":"","url":"https://api.github.com/users/Gcaufy","html_url":"https://github.com/Gcaufy","followers_url":"https://api.github.com/users/Gcaufy/followers","following_url":"https://api.github.com/users/Gcaufy/following{/other_user}","gists_url":"https://api.github.com/users/Gcaufy/gists{/gist_id}","starred_url":"https://api.github.com/users/Gcaufy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gcaufy/subscriptions","organizations_url":"https://api.github.com/users/Gcaufy/orgs","repos_url":"https://api.github.com/users/Gcaufy/repos","events_url":"https://api.github.com/users/Gcaufy/events{/privacy}","received_events_url":"https://api.github.com/users/Gcaufy/received_events","type":"User","site_admin":false},"created_at":"2018-03-05T02:10:27Z","updated_at":"2018-03-05T02:10:27Z","author_association":"COLLABORATOR","body":"1.7.2的版本中支持了原生组件，大家可以试一下这个版本，应该能解决repeat下的一些问题：\r\n\r\n安装使用：\r\n```\r\nnpm install wepy-cli@1.7.2-alpha1 -g\r\nnpm install wepy@1.7.2-alpha1 --save\r\nwepy build --no-cache\r\n```\r\n文档说明：https://github.com/Tencent/wepy/blob/component/docs/md/doc.md#%E7%BB%84%E4%BB%B6\r\n迁移参考：https://github.com/wepyjs/wepy-wechat-demo/commit/5f84a3aed82547d7db4eb816f5c83f5ad35eba65"}}
{"actor":{"display_login":"Gcaufy"}}