This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{define "content" -}} | |
<div class="container"> | |
<h3 class="title"> organic products </h3> | |
<div class="products-container"> | |
{{range $index, $item :=.}} | |
<div class="product" data-name="p-{{$index}}"> | |
<img src="{{$item.Img}}" alt=""> | |
<h3>{{$item.Name}}</h3> | |
<div class="price">{{$item.Price}}</div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"io/ioutil" | |
"fyne.io/fyne/v2" | |
"fyne.io/fyne/v2/layout" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func loadJsonData() []string { | |
fmt.Println("Loading data from JSON file") | |
input, _ := ioutil.ReadFile("data.json") | |
var data []string | |
json.Unmarshal(input, &data) | |
fmt.Println(data) | |
return data | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func saveJsonData(data binding.StringList) { | |
fmt.Println("Saving data to JSON file") | |
d, _ := data.Get() | |
jsonData, _ := json.Marshal(d) | |
ioutil.WriteFile("data.json", jsonData, 0644) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myApp := app.New() | |
myWindow := myApp.NewWindow("List Data") | |
loadedData := loadJsonData() | |
data := binding.NewStringList() | |
data.Set(loadedData) | |
defer saveJsonData(data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list := widget.NewListWithData(data, | |
func() fyne.CanvasObject { | |
return widget.NewLabel("template") | |
}, | |
func(i binding.DataItem, o fyne.CanvasObject) { | |
o.(*widget.Label).Bind(i.(binding.String)) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list.OnSelected = func(id widget.ListItemID) { | |
list.Unselect(id) | |
d, _ := data.GetValue(id) | |
w := myApp.NewWindow("Edit Data") | |
itemName := widget.NewEntry() | |
itemName.Text = d | |
updateData := widget.NewButton("Update", func() { | |
data.SetValue(id, itemName.Text) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add := widget.NewButton("Add", func() { | |
w := myApp.NewWindow("Add Data") | |
itemName := widget.NewEntry() | |
addData := widget.NewButton("Add", func() { | |
data.Append(itemName.Text) | |
w.Close() | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exit := widget.NewButton("Quit", func() { | |
myWindow.Close() | |
}) | |
myWindow.SetContent(container.NewBorder(nil, container.New(layout.NewVBoxLayout(), add, exit), nil, nil, list)) | |
myWindow.Resize(fyne.NewSize(400, 600)) | |
myWindow.SetMaster() | |
myWindow.CenterOnScreen() | |
myWindow.ShowAndRun() |