Meteor dynamic input fields

我怕爱的太早我们不能终老 提交于 2019-12-24 12:01:51

问题


I'm looking for a way to create dynamic input fields in Meteor.js. I've chosen not to use Aldeed's Autoform for greater control over the code. From front end point of view I have no issues to add dynamic fields with +/- button to add and remove fields. What I'm struggling with is the insert statement on the back end. How can one add dynamic insert in Meteor.js? Cheers!


回答1:


Essentially you need a reactive array of element that's rendered to the DOM via {{#each}} ... {{/each}}. When the array changes the DOM would re-render.

There's no need to create your own reactive array, there's one here with an example that does exactmy what you're asking for:

http://reactivearray.meteor.com/

However I'd recommend going one step further and using the ViewModel package for this (by the same author). Here's an example which shows how to use it to insert fields:

http://viewmodel.meteor.com/#contacts

Tim




回答2:


Thanks Tim, these are both pretty useful. I'm using Collection 2 so decided to use objects ('object.$'). This is easy solution for me. cheers.



来源:https://stackoverflow.com/questions/29061719/meteor-dynamic-input-fields

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!