Vapor pass data from postgres to a leaf template
You're correct in that you need to handle the future but you should use flatMap
since the render call returns a future. So your code should look like:
func routes(_ app: Application) throws {
app.get("all") { req -> EventloopFuture<View> in
return Todo.query(on: req.db).all().flatMap { todos in
let context = TodoContext(todos: todos)
return req.view.render("index", context)
}
}
}
How to pass ResultSet from MySql for Swift to leaf template contest
You should be able to fix this by manually setting the type of the dictionary array to Node
:
drop.get("report") {req in
let data = try mysql.execute("select * from things")
let dataNode = Node.array(data.map({ return Node.object($0) }))
return try drop.view.make("report", ["data":dataNode])
}
Thymeleaf: pass input text as parameter in form action
This doesn't work like this. Like all server side technologies Thymeleaf templates are executed before being sent to the user, so it can't know what the user will enter and insert it into the action
attribute.
You could do something similar with JavaScript, but it would be much easier to use a regular HTML form. That requires you not to use a path variable, but a request parameter in your controller:
@PostMapping("/postEndpoint")
public String pidUserSubmit(@RequestParam(name = "myid") String myid) {
log.debug("*** MY ID: {}", myid);
return "redirect:/someOtherPage";
}
<form th:action="@{/postEndpoint}" th:object="${mymodelobject}">
<input name="myid" type="text" th:value="*{myid}">
</form>
(Don't forget to use th:object
with an object that has a property myid
, if you want to use the *{...}
syntax.)
Related Topics
Dynamic Links Firebase Function Not Being Called at All Xcode 12
Realm Write Transaction Failing, Despite Being in Transaction
Swiftui Go Back Programmatically from Representable to View
Actions Assigned to Nsmenuitem Dont Seem to Work
Sdwebimage, Swift: Sdwebimagerefreshcached Unresolved Identifier
Aurendercallbackstruct in Swift
Multiple Scatterplots Using Core Plot and Swift
Swiftui JSON Won't Print Title in Scrollview Hstack (But Will in List)
Delete Tableview Cell, and Remove Data from Firebase
Tableview to Display Different Images on New Controller
What's The Difference Between Nsusernotification and Unusernotification in Macos
Can't Override UItableviewdatasource and UItableviewdelegate
Uitableview Didselectrow Returns Wrong Row Index Value
Extension for Average to Return Double from Numeric Generic
Parse Weird Bug in Swift That Causes Acl Write Permissions to Change to an Objectid
What's The Correct Number Type for Financial Variables in Swift
Could Not Find Member <Method Name> for Struct Type in Swift