简体   繁体   English

Meteorjs编辑按钮,并从一个列表中删除,添加到另一个列表中

[英]Meteorjs edit button and removing from one list adding to other

This is my first project with meteor and I am a heavy newbie. 这是我与流星的第一个项目,我是个新手。 Need help with this. 需要帮助。 Three questions. 三个问题。 I want when I press the edit button to focus on text of a task and I can change it... something like this: 我想按编辑按钮将焦点放在任务的文本上,然后可以对其进行更改...如下所示:

<button class="editItem">Edit</button> 

and after that I can edit text of that li , this is the functionality: 然后,我可以编辑该li文本,这是功能:

editTask: function(id, todoItem){ 
   Tasks.update({_id: id}, {$set: { title:todoItem }}); 
}

And I'm able to do it if I have input type field, but how to do that with a button (I want to turn ordinary text into input field). 如果我有输入类型字段,那么我就能做到,但是如何用按钮做到这一点(我想将普通文本变成输入字段)。

Second question: I have two columns, To Do and Done : 第二个问题:我有两栏, To DoDone

<template name="task"> 
  <li>
    <span class="text">{{title}}</span></li>
    <button class="completed">Completed</button>
    <li><input type="text" name="task" class="edit"></li>
    <button class="saveItem">Save</button>
    <button class="cancelItem">Cancel</button>
    <button class="editItem">Edit</button>
    <button class="delete">Delete</button>
    <input type="checkbox" checked="{{checked}}" class="completed">
  </li>
</template> 
<template name="taskDone">
 <li>
  <div>
    <span class="text">{{title}}</span>
  </div>
 </li>
</template>

How can I hide completed tasks from To Do list and show up in Done list? 如何从To Do列表中隐藏已完成的任务并显示在Done列表中? Maybe display true or false when I press the button Completed but I cannot pin point the exact way. 当我按下“ Completed ”按钮时,可能会显示是或否,但我无法指出确切的方法。

I tried playing with checked state but that isn't what I need. 我尝试过检查状态,但这不是我所需要的。

First off you have an incorrect number of <li> tags in your example code (you close the first li at the end of the span and then continue onwards as if it still were the same li). 首先,示例代码中的<li>标记数量不正确(您在跨度结尾处关闭了第一个li,然后继续继续,就像仍然是相同的li一样)。

Add a completed field to your collection, set initially to always "no" when you create a task. 将完成的字段添加到您的集合,创建任务时最初设置为始终为“ no”。

What you want to do then, is set the span as contenteditable set to true with an onclick event. 然后,您要执行的操作是使用onclick事件将范围设置为contenteditable设置为true。 Do not use it as an helper as you currently do: use events! 不要像现在那样将其用作帮助器:使用事件! Something like here: Meteor - Is there a way to get div contenteditable two way data binding to work? 像这样的东西: 流星-有没有办法让div contenteditable两种方式的数据绑定起作用? Or here in simple jquery: HTML5 contentEditable with jQuery 或者在简单的jquery中: HTML5 contentEditable with jQuery

Then when you click save you need to set it as false and update the completed field to say "yes" or something the like. 然后,当您单击保存时,需要将其设置为false并更新完成的字段以说“是”或类似内容。

Then the way you just simple filter the collection differently for the todo tasks and the completed ones: in the template task you will do something like Tasks.find({}, {fields: {"completed": "no"}}); 然后,您以简单的方式对待办任务和完成的任务进行不同的筛选:在模板任务中,您将执行Tasks.find({}, {fields: {"completed": "no"}}); In the template taskDone: 在模板taskDone中:

Tasks.find({}, {fields:{"completed": "yes"}});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM