浏览代码

Merge branch 'nztqa-fix-checklist' into devel

Fix duplicate id generation. Thanks to nztqa ! Closes #1090
Lauri Ojansivu 8 年之前
父节点
当前提交
b0367491b9
共有 2 个文件被更改,包括 9 次插入2 次删除
  1. 2 1
      CHANGELOG.md
  2. 7 1
      models/checklists.js

+ 2 - 1
CHANGELOG.md

@@ -7,7 +7,8 @@ This release adds the following new features:
 and fixes the following bugs:
 and fixes the following bugs:
 
 
 * [Fix incorrect attachment link with subfolder in the url](https://github.com/wekan/wekan/pull/1086);
 * [Fix incorrect attachment link with subfolder in the url](https://github.com/wekan/wekan/pull/1086);
-* [Fix link to card](https://github.com/wekan/wekan/pull/1087).
+* [Fix link to card](https://github.com/wekan/wekan/pull/1087);
+* [Fix duplicate id generation](https://github.com/wekan/wekan/pull/1093).
 
 
 Thanks to GitHub users kubiko and nztqa for their contributions.
 Thanks to GitHub users kubiko and nztqa for their contributions.
 
 

+ 7 - 1
models/checklists.js

@@ -86,7 +86,13 @@ Checklists.mutations({
   //for items in checklist
   //for items in checklist
   addItem(title) {
   addItem(title) {
     const itemCount = this.itemCount();
     const itemCount = this.itemCount();
-    const _id = `${this._id}${itemCount}`;
+    let idx = 0;
+    if (itemCount > 0) {
+      const lastId = this.items[itemCount - 1]._id;
+      const lastIdSuffix = lastId.substr(this._id.length);
+      idx = parseInt(lastIdSuffix, 10) + 1;
+    }
+    const _id = `${this._id}${idx}`;
     return { $addToSet: { items: { _id, title, isFinished: false } } };
     return { $addToSet: { items: { _id, title, isFinished: false } } };
   },
   },
   removeItem(itemId) {
   removeItem(itemId) {