0
我已經用Nodejs/Express創建了API。 讓我說我可以做localhost:8080/list
的GET請求,它返回我的TODO列表的JSON,我可以發佈到localhost:8080/list
創建新的待辦事項列表。如何從RiotControl Store ajax調用?
然後我用我的前端網站Riotjs + Riotcontrol。 如何從todostore.js文件請求?
這是todostore.js文件riotcontrol這是我從riotcontrol演示文件夾獲取
// TodoStore definition.
// Flux stores house application logic and state that relate to a specific domain.
// In this case, a list of todo items.
function TodoStore() {
riot.observable(this) // Riot provides our event emitter.
var self = this
self.todos = [
{ title: 'Task 1', done: false },
{ title: 'Task 2', done: false }
]
// Our store's event handlers/API.
// This is where we would use AJAX calls to interface with the server.
// Any number of views can emit actions/events without knowing the specifics of the back-end.
// This store can easily be swapped for another, while the view components remain untouched.
self.on('todo_add', function(newTodo) {
self.todos.push(newTodo)
self.trigger('todos_changed', self.todos)
})
self.on('todo_remove', function() {
self.todos.pop()
self.trigger('todos_changed', self.todos)
})
self.on('todo_init', function() {
self.trigger('todos_changed', self.todos)
})
// The store emits change events to any listening views, so that they may react and redraw themselves.
}