<p>Scenario</p>
<p>I am using database/sql to query a database using db.Query and am placing the data from the table into a slice of structs. At this point i am displaying the information in my template by ranging over the slice and displaying the info. This is actually working the way I intended it to.</p>
<p>One of the fields is displays date information and I would like to include a date select field on the template to allow the user to only show dates after a date.</p>
<p>How should I go about handling this? </p>
<p>The options that I have considered so far
1) write front end code to handle filtering on the client machine
2) POST date from date field and use POST data to re-query the database and display new information.</p>
<p>I am new to go so any ideas, guidance or criticism is welcome.</p>
<hr/>**评论:**<br/><br/>mvansickle: <pre><p>Could you register a custom function with the template that would do the server side work for you? (ref <a href="https://golang.org/pkg/text/template/#Template.Funcs" rel="nofollow">https://golang.org/pkg/text/template/#Template.Funcs</a>)</p></pre>thewhitetulip: <pre><ol>
<li>Fetch data</li>
<li>Slice data based on your condition</li>
<li>Render template</li>
<li>Handling the forms on the backend
For more details read my tutorial :-)
<a href="https://github.com/thewhitetulip/web-dev-golang-anti-textbook" rel="nofollow">https://github.com/thewhitetulip/web-dev-golang-anti-textbook</a></li>
</ol></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传