Skip to content

Commit

Permalink
refine features example and fix #7
Browse files Browse the repository at this point in the history
  • Loading branch information
oskca committed Feb 24, 2017
1 parent 19d6da4 commit 88ef33b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
13 changes: 7 additions & 6 deletions examples/features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Todo struct {

func NewTodo(content string) *Todo {
t := &Todo{
Object: js.Global.Get("Object"),
Object: js.Global.Get("Object").New(),
}
t.Time = time.Now().String()
t.Content = content
Expand Down Expand Up @@ -61,14 +61,14 @@ func (m *Model) Repeat() {
func (m *Model) PopulateTodo() {
// using append would cause GopherJS internalization problems
// so it's better to use VueJS ops to manipulates the array
m.Todos = append(m.Todos, NewTodo(m.Str))
// vm := vue.GetVM(m)
// todos := vm.Get("todos")
// m.Todos = append(m.Todos, NewTodo(m.Str))
vm := vue.GetVM(m)
todos := vm.Get("todos")
// println("ok 0", todos, todos.Get("length"))
// println("ok 1", todos, todos.Length())
// println("ok 2", m.Todos, len(m.Todos))
// vue.Unshift(todos, NewTodo(m.Str))
// vue.Push(todos, NewTodo(m.Str))
vue.Push(todos, NewTodo(m.Str))
}

func (m *Model) MapTodos() {
Expand Down Expand Up @@ -104,7 +104,8 @@ func (m *Model) DoubleInt() int {

func main() {
// register a time formating filter
vue.NewFilter(func(t time.Time) string {
vue.NewFilter(func(v *js.Object) interface{} {
t, _ := time.Parse("2006-01-02 15:04:05.999999999 -0700 MST", v.String())
return t.Format("2006-01-02 15:04:05")
}).Register("timeFormat")
// begin vm
Expand Down
5 changes: 1 addition & 4 deletions examples/features/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,9 @@
{{ item }}
</li>
<input v-model="str" />
<br>
wtf: {{wtf}}
<br>
Todos:<br>
<ul v-for="todo in todos">
<li>{{todo.time }} - {{todo.content}}</li>
<li>{{todo.time | timeFormat}} - {{todo.content}}</li>
</ul>
<p>{{str}}</p>
</div>
Expand Down

0 comments on commit 88ef33b

Please sign in to comment.