<p><strong>EDIT:</strong> I just re-read my post and realized that it sounds like I'm not using go. I am using go 1.10 and gin is what i'm using to route all the traffic and stuff. Sorry about not giving you more context.</p>
<p>I'm adding a new feature to a website that will make a new "schedule". Currently the schedule is a daily thing without consideration for holidays but the feature being added is to start considering holidays in this schedule. I'm bad at front end things like this so what I've come up with so far is a bootstrap modal that is opened and controlled with jquery. (FYI I'm not sold on having jquery and bootstrap but it's existing code and i'm trying to make as small of changes as possible. and slowly introduce big changes and refactoring) So my question is this: what is a fairly typical solution to show a "new ____ form" that posts a model to the API to be saved into a database. The backend stuff is working and last night I was able to get JQuery to get all my values from the inputs and create a object that got posted to the API. (For reference)</p>
<pre><code> function submitNewScheduleFromModal() {
var record = {
'circuitnum': parseInt($("#newScheduleForm #circuitNumber").val()),
'ontime': 'Dusk-0',
'offtime': 'Dawn-0',
'sun': $("#newScheduleForm #sun").is(":checked"),
'mon': $("#newScheduleForm #mon").is(":checked"),
'tue': $("#newScheduleForm #tue").is(":checked"),
'wed': $("#newScheduleForm #wed").is(":checked"),
'thu': $("#newScheduleForm #thu").is(":checked"),
'fri': $("#newScheduleForm #fri").is(":checked"),
'sat': $("#newScheduleForm #sat").is(":checked"),
'enabled': true
};
$.ajax({
url: `${globalUrl}/schedule2`,
data: JSON.stringify(record),
contentType: "application/json; charset=utf-8",
dataType: "json",
method: 'POST'
})
.done(function () {
window['grid' + record.circuitnum].reload();
})
.fail(function (jqXHR, textStatus, errorThrown) {
console.log('Failed to add' + textStatus);
});
}
</code></pre>
<p>I'm currently stuck trying to figure out how I can make the ontime and offtime dropdown boxes a little more dynamic and generated in nature instead of the 240 lines of code that append a select tag...( yeah wonderful :/) which got me thinking about do I write my modal in go then serve it up? If so how would I write this modal as a template and ask for a new one each time? Things I just don't know.</p>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传