@@ -8,15 +8,16 @@ import (
8
8
"time"
9
9
)
10
10
11
+ // no *js.Object struct can only be manipulated by ViewModel.methods
11
12
type Todo struct {
12
- * js.Object
13
- Time string `js:"time "`
14
- Content string `js:"content "`
13
+ // *js.Object
14
+ Time string // `js:"Time "`
15
+ Content string // `js:"Content "`
15
16
}
16
17
17
18
func NewTodo (content string ) * Todo {
18
19
t := & Todo {
19
- Object : js .Global .Get ("Object" ).New (),
20
+ // Object: js.Global.Get("Object").New(),
20
21
}
21
22
t .Time = time .Now ().Format ("15:04 05:06" )
22
23
t .Content = content
@@ -41,10 +42,6 @@ func (m *Model) Inc() {
41
42
42
43
func (m * Model ) Repeat () {
43
44
m .Str = strings .Repeat (m .Str , 3 )
44
- }
45
-
46
- func (m * Model ) PopulateTodo () {
47
- m .Todos = append (m .Todos , NewTodo (m .Str ))
48
45
vm := vue .GetVM (m )
49
46
println ("Get(m):" , vm )
50
47
println ("m keys:" , js .Keys (m .Object ))
@@ -58,8 +55,18 @@ func (m *Model) PopulateTodo() {
58
55
println ("integer from vm:" , vm .Get ("integer" ).Int ())
59
56
}
60
57
58
+ func (m * Model ) PopulateTodo () {
59
+ // m.Todos = append(m.Todos, NewTodo(m.Str))
60
+ vm := vue .GetVM (m )
61
+ todos := vm .Get ("todos" )
62
+ todos .Unshift (NewTodo (m .Str ))
63
+ }
64
+
61
65
func (m * Model ) ShiftTodo () {
62
- m .Todos = m .Todos [1 :]
66
+ // m.Todos = m.Todos[1:]
67
+ vm := vue .GetVM (m )
68
+ todos := vm .Get ("todos" )
69
+ todos .Shift ()
63
70
}
64
71
65
72
func (m * Model ) WhatTF () string {
0 commit comments