For tag communication you can send parameters in the tag and then in the child use the opts object. (In case you need it, here is a tutorial about tag communication http://vitomd.com/blog/coding/tag-communication-in-riot-js-part-1/)
Here is a sample (removing the async functionality as that is another problem)
As you can see I used 'todo in todos' to get a reference for the current record and then I pass a parameter called t with the record.
Then in the todo tag I access the records using opts and t that is the parameter.
{ opts.t.due_date }
Also I used on('mount') that it will execute when mounting the tag, and this.update() to force an update. and self= this to maintain the context
var self = this
this.todos = []
this.on('mount', function(){
self.todos = self.allTodos()
self.update()
})
Here is the simplified code
Issues
var self = this
this.todos = []
this.on('mount', function(){
self.todos = self.allTodos()
self.update()
})
allTodos(){
var test = [{done:'true', due_date:'11', title:'the title'}, {done:'true', due_date:'11', title:'the title'}]
return test
}
{ opts.t.title } | { opts.t.due_date } Delete |
And about the async function I think that you can call self.update() in the success callback function to rerender the todos and just assign the data to
self.todos = data
var self = this
allTodos(){
var url = 'http://myurl.com/projects'; //random adress
$.ajax({
url: url,
type: "GET",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(data) {
self.todos = data
self.update()
}
});
}