我正在从Meteor教程构建todo应用程序并继续它。我正在根据任务模型构建一些列表,但我不知道如何加入它们并说当我点击一个列表时,我想要从这个列表中完成所有任务。
目前,我的Tasks.js包含:
___[MOD]
| M A N I F E S T
|___[NSP] CSCICom_Usable
| |___[INT] CSCICom_Usable.Class1
| | | .class interface public abstract auto ansi import
| | | implements CSCICom_Usable._Class1
| | | .custom instance void [mscorlib]System.Runtime.InteropServices.GuidAttribute::.ctor(string) = ( 01 00 24 32 34 42 33 31 37 34 37 2D 41 46 42 36 // ..$24B31747-AFB6 ...
| | | .custom instance void [mscorlib]System.Runtime.InteropServices.CoClassAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 1A 43 53 43 49 43 6F 6D 5F 55 73 61 62 6C // ...CSCICom_Usabl ...
| |
| |___[CLS] CSCICom_Usable.Class1Class
| | | .class public auto ansi import
| | | implements CSCICom_Usable._Class1
| | | implements CSCICom_Usable.Class1
| | | .custom instance void [mscorlib]System.Runtime.InteropServices.TypeLibTypeAttribute::.ctor(valuetype [mscorlib]System.Runtime.InteropServices.TypeLibTypeFlags) = ( 01 00 02 00 00 00 00 00 ) ...
| | | .custom instance void [mscorlib]System.Runtime.InteropServices.GuidAttribute::.ctor(string) = ( 01 00 24 37 32 43 45 36 35 44 45 2D 46 30 42 38 // ..$72CE65DE-F0B8 ...
| | | .custom instance void [mscorlib]System.Runtime.InteropServices.ClassInterfaceAttribute::.ctor(valuetype [mscorlib]System.Runtime.InteropServices.ClassInterfaceType) = ( 01 00 00 00 00 00 00 00 ) ...
| | |___[MET] .ctor : void()
| | |___[MET] GetIncidentCodes : class [VBA]VBA.Collection()
| |
| |___[INT] CSCICom_Usable.Class2
| | | .class interface public abstract auto ansi import
| | | implements CSCICom_Usable._Class2
| | | .custom instance void [mscorlib]System.Runtime.InteropServices.GuidAttribute::.ctor(string) = ( 01 00 24 41 38 38 36 33 32 42 42 2D 41 46 46 31 // ..$A88632BB-AFF1 ...
| | | .custom instance void [mscorlib]System.Runtime.InteropServices.CoClassAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 1A 43 53 43 49 43 6F 6D 5F 55 73 61 62 6C // ...CSCICom_Usabl ...
| |
| |___[CLS] CSCICom_Usable.Class2Class
| | | .class public auto ansi import
| | | implements CSCICom_Usable._Class2
| | | implements CSCICom_Usable.Class2
| | | .custom instance void [mscorlib]System.Runtime.InteropServices.TypeLibTypeAttribute::.ctor(valuetype [mscorlib]System.Runtime.InteropServices.TypeLibTypeFlags) = ( 01 00 02 00 00 00 00 00 ) ...
| | | .custom instance void [mscorlib]System.Runtime.InteropServices.GuidAttribute::.ctor(string) = ( 01 00 24 41 30 43 39 46 42 45 45 2D 42 36 45 38 // ..$A0C9FBEE-B6E8 ...
| | | .custom instance void [mscorlib]System.Runtime.InteropServices.ClassInterfaceAttribute::.ctor(valuetype [mscorlib]System.Runtime.InteropServices.ClassInterfaceType) = ( 01 00 00 00 00 00 00 00 ) ...
| | |___[MET] .ctor : void()
| | |___[MET] get_Code : int16()
| | |___[MET] get_Name : string()
| | |___[MET] set_Code : void(int16)
| | |___[MET] set_Name : void(string)
| | |___[PTY] Code : int16()
| | |___[PTY] Name : string()
| |
| |___[INT] CSCICom_Usable._Class1
| | | .class interface public abstract auto ansi import
| | | .custom instance void [mscorlib]System.Runtime.InteropServices.TypeLibTypeAttribute::.ctor(valuetype [mscorlib]System.Runtime.InteropServices.TypeLibTypeFlags) = ( 01 00 D0 10 00 00 00 00 ) ...
| | | .custom instance void [mscorlib]System.Runtime.InteropServices.GuidAttribute::.ctor(string) = ( 01 00 24 32 34 42 33 31 37 34 37 2D 41 46 42 36 // ..$24B31747-AFB6 ...
| | |___[MET] GetIncidentCodes : class [VBA]VBA.Collection()
| |
| |___[INT] CSCICom_Usable._Class2
| | | .class interface public abstract auto ansi import
| | | .custom instance void [mscorlib]System.Runtime.InteropServices.TypeLibTypeAttribute::.ctor(valuetype [mscorlib]System.Runtime.InteropServices.TypeLibTypeFlags) = ( 01 00 D0 10 00 00 00 00 ) ...
| | | .custom instance void [mscorlib]System.Runtime.InteropServices.GuidAttribute::.ctor(string) = ( 01 00 24 41 38 38 36 33 32 42 42 2D 41 46 46 31 // ..$A88632BB-AFF1 ...
| | |___[MET] get_Code : int16()
| | |___[MET] get_Name : string()
| | |___[MET] set_Code : void(int16)
| | |___[MET] set_Name : void(string)
| | |___[PTY] Code : int16()
| | |___[PTY] Name : string()
| |
|
Body.js
'tasks.insert'(text, privacy, priority, listId) {
...
Tasks.insert({
text,
listId: listId,
owner: this.userId,
username: Meteor.users.findOne(this.userId).username,
});
},
然后我在哪里展示它:
Template.body.events({
'submit .new-task' (event) {
event.preventDefault();
const listId = ???
const target = event.target;
const text = target.text.value;
...
Meteor.call('tasks.insert', text, privacy, priority, listId);
...
},
我的body.html,我只是分别显示每个项目(列表和任务)。但问题是我不知道如何建立两者之间的关系......
你能帮我吗?
非常感谢
答案 0 :(得分:1)
我看到你已经在使用Session了。基本上,您将使用一个Session变量来跟踪用户选择的列表,然后使用该变量过滤您的任务。
在您正在显示列表名称的正文中,将列表的ID添加为HTML属性:
{{#each lists}}
<a href='#' class='list-name' data-id='{{this._id}}'>
{{this.name}}
</a>
{{/each}}
添加一个事件,用于单击将其id保存到Session变量的列表名称:
Template.body.events({
'click .list-name' (event) {
event.preventDefault();
Session.set('listId', event.currentTarget.attr('data-id'))
}
})
在tasks
帮助器中,使用Session变量过滤查询:
return Tasks.find(
{ listId: Session.get('listId') },
{ sort: Session.get("sort_order") }
);
如果有什么事情可以更清楚,请告诉我。