0

Note我有一个简单的剑道列表视图,其中包含来自四个对象的数组的静态数据

var notes = [{"note_id":1,"content":"This is Note 1","created":"2019-05-08 00:39:34"},
            {"note_id":2,"content":"This is note 2","created":"2015-06-04 15:49:26"},
            {"note_id":3,"content":"This is note 3","created":"2015-06-03 15:49:26"},
            {"note_id":4,"content":"This is note 4","created":"2015-06-02 15:49:26"}];

我有单独template的 s 用于显示和编辑 Notes

<script type="text/x-kendo-tmpl" id="NoteTemplate">
        <div class="product-view k-widget">
            <dl>
                <dt>#:kendo. toString(created, "dd/MM/yyyy HH:mm")#</dt>
                <dd>#=(content)#</dd>
            </dl>
            <div class="edit-buttons">
                <a class="k-button k-edit-button" href="\\#"><span class="k-icon k-i-edit"></span></a>
                <a class="k-button k-delete-button" href="\\#"><span class="k-icon k-i-close"></span></a>
            </div>
        </div>
        <input type="hidden" name="type_id" value="0" data-bind="value:type_id" />
</script>

<script type="text/x-kendo-tmpl" id="NoteEditTemplate">
        <div class="product-view k-widget">
            <dl>
                <dt>#:kendo. toString(created, "dd/MM/yyyy HH:mm")#</dt>
                <dd>
                    <div data-bind="value:content">
                #=content#
                    </div>
                </dd>

            <div class="edit-buttons">
                <a class="k-button k-update-button" href="\\#"><span class="k-icon k-i-check"></span></a>
                <a class="k-button k-cancel-button" href="\\#"><span class="k-icon k-i-cancel"></span></a>
            </div>
        </div>
</script>

问题是,当用户点击“铅笔”图标编辑“Note 2”时,编辑模板被渲染,但带有 Note 3 的模型

如果用户取消编辑更多,他们再次看到显示模板渲染注2

因此,当我们进入编辑模式时,Kendo 组件似乎正在从 Note 2 切换到 note 3... 为什么会这样?

在此处查看正在运行的演示: https ://dojo.telerik.com/oNosOCUv/3

4

1 回答 1

1

我做了3个改变:-

将模式添加到数据源。

在 EditNoteTemplate 中关闭 dl 标签。

将隐藏的输入移到父 div 中,因为 Kendo 正在将数据 uid 分配给该元素。 查看呈现的 HTML 元素

<script type="text/x-kendo-tmpl" id="NoteTemplate">
        <div class="product-view k-widget">
            <dl>
                <dt>#:kendo. toString(created, "dd/MM/yyyy HH:mm")#</dt>
                <dd >#=(content)#</dd>
                <input type="hidden" name="type_id" value="0" data-bind="value:type_id" />
            </dl>
            <div class="edit-buttons">
                <a class="k-button k-edit-button" href="\\#"><span class="k-icon k-i-edit"></span></a>
                <a class="k-button k-delete-button" href="\\#"><span class="k-icon k-i-close"></span></a>
            </div>
        </div>      
</script>

<script type="text/x-kendo-tmpl" id="NoteEditTemplate">
        <div class="product-view k-widget">
            <dl>
                <dt>#:kendo. toString(created, "dd/MM/yyyy HH:mm")#</dt>
                <dd>
                    <div data-bind="value:content">
                        #=content#
                    </div>
                </dd>
            </dl>
            <div class="edit-buttons">
                <a class="k-button k-update-button" href="\\#"><span class="k-icon k-i-check"></span></a>
                <a class="k-button k-cancel-button" href="\\#"><span class="k-icon k-i-cancel"></span></a>
            </div>
        </div>
</script>

  <script>

    var notes = [
                        {"note_id":1,"content":"This is Note 1","created":"2019-05-08 00:39:34"},
                        {"note_id":2,"content":"This is note 2","created":"2015-06-04 15:49:26"},
                        {"note_id":3,"content":"This is note 3","created":"2015-06-03 15:49:26"},
                        {"note_id":4,"content":"This is note 4","created":"2015-06-02 15:49:26"}
                ];

    $(document).ready(
            function() {    
                var dataSource = new kendo.data.DataSource({   
                                 data: notes,
                                 schema: {
                                   model: {
                                   id: "note_id",
                                   fields: {
                                    note_id: { type: "number" },
                                    content: { type: "string" },
                                    created: { type: "date" }
                                   }
                                }
                            }});

                var listView = $("#notes-list").kendoListView({
                    dataSource: dataSource, 
                    template: kendo.template($("#NoteTemplate").html()),
                    editTemplate: kendo.template($("#NoteEditTemplate").html()) 
                }).data("kendoListView");
      });
  </script>

  <div id="notes-list"></div>
于 2019-05-09T13:12:06.243 回答