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

列表渲染出来的多个勾选框绑定到同一数组目测有bug #141

Closed
jiangshanmeta opened this issue Oct 11, 2016 · 1 comment
Closed

Comments

@jiangshanmeta
Copy link

在线demo

`

<script src="http://cn.vuejs.org/js/vue.js"></script>
    <div id="wrap">
        <ul>
            <li v-for="item in checkbox">
                {{item.question}}
                <ul >
                    <li v-for="option in item.options">
                        <label>
                            <input value="{{option.val}}" v-model="answers[$parent.$index]" type="checkbox">
                            {{option.desc}}
                        </label>
                    </li>
                </ul>
            </li>
        </ul>
        <button v-on:click="dump">log</button>
    </div>
    <script>
        new Vue({
            el:"#wrap",
            data:{
                checkbox:[
                    {
                        'question':'question1',
                        'options':[
                            {'desc':'optionA1','val':'A'},
                            {'desc':'optionB1','val':'B'},
                            {'desc':'optionC1','val':'C'},
                        ],
                    },
                    {
                        'question':'question2',
                        'options':[
                            {'desc':'optionA2','val':'A'},
                            {'desc':'optionB2','val':'B'},
                            {'desc':'optionC2','val':'C'},
                        ],
                    },
                    {
                        'question':'question3',
                        'options':[
                            {'desc':'optionA3','val':'A'},
                            {'desc':'optionB3','val':'B'},
                            {'desc':'optionC3','val':'C'},
                        ],
                    },


                ],
                answers:[],
            },
            methods:{
                dump:function(){
                    console.log(this.answers)
                }
            },
            ready:function(){
                var len = this.checkbox.length;
                for(var i=0;i<len;i++){
                    this.answers[i] = [];
                }
            }

        });

    </script>

`

根据多个勾选框,绑定到同一个数组这个例子写的,在ready的时候根据checkbox的组数把answers中对应的项初始化为一个空array,每一个空array对应教程中的checkedNames,但是当点击任意一个checkbox的时候,其绑定的array转换成了bool,选择其它的checkbox对应的array依然保持array类型,并能向官网demo中的一样正常绑定到同一个数组中。

目测是bug。

Jinjiang pushed a commit that referenced this issue Nov 4, 2016
@Jinjiang
Copy link
Member

Jinjiang commented Nov 4, 2016

Sorry 这里只是讨论中文文档翻译,这个问题最好还是在 vue 主仓库的 issue 里讨论,会有更多人帮助你,并且鼓励使用英文
谢谢

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