Skip to content

チェックボックスにアイテムデータをバインドし、attr(checked):checkedを操作してもpropに反映されません #267

@TomuroYuki

Description

@TomuroYuki

チェックボックスにデータアイテムをバインドし、イベントでチェックボックスを選択/未選択に変更させようとしました。attributeをchecked/nullに変更してもpropが対応(checkedならtrue、nullならfalse)しませんでした。
そのためイベントを実行してattributeはcheckedでもチェックボックスに✔が入りませんでした。

View(コメントビュー部分)

<!--{h5view id="tmplTodos"}
    <header id="header">
        <h1>todos</h1>
        <input id="new-todo" placeholder="What needs to be done?" autofocus>
    </header>
    <section id="main">
        <input type="checkbox" id="toggle-all">
        <ul id="todo-list" data-h5-loop-context="todos">
            <li>
                <input type="hidden" data-h5-bind="id" />
                <input type="checkbox" class="toggle" data-h5-bind="attr(checked):checked" />
                <label data-h5-bind="content"></label>
                <button class="destroy" id="btnDel"></button>
            </li>
        </ul>
    </section>
-->

データモデル

status : {
        type : 'boolean'
    },
    checked : {
        type : 'string',
        depend : {
            on : 'status',
            calc : function() {
                return this.get('status') ? 'checked' : null;
            }
        }
    },

Logic(イベントで呼ばれるロジック)

toggleStatus : function() {
        var len = this.todos.length;

        for (var i = 0; i < len; i++) {
            var item = this.todos.get(i);

            // 一つでもstatusがfalseならば、全てtrueにする。
            if (item.get('status') == false) {
                for (var j = 0; j < len; j++) {
                    this.todos.get(j).set('status', true);
                }
                return true;
            }
            item.set('status', false);
        }
        return false;
    },

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions