I need to know how to refresh the bindings in Aurelia. I have been "Googling" for some time now, but can't seem to find the answer. The reason I need to refresh bindings is because some of the html (with click.delegate
bindings) is generated after a call to server to retrieve data. I am updating a grid with some "Edit" and "Delete" buttons. Anyway, when I was using Durandal / KnockoutJS, I did the following:
var body = this.element.find("tbody")[0];
if (body) {
ko.cleanNode(body);
ko.applyBindings(ko.dataFor(body), body);
}
How do I do the same thing in Aurelia?
UPDATE:
Thanks @fred-kleuver for your response. I am not sure that is relevant in my case and it does seem like overkill for what I want to do. It may be that I need to do as you've suggested, but before I delve into figuring that all out, let me provide further details here of exactly what I am doing, as you might have a simpler solution for me:
I am using Kendo UI (the old GPL version from early 2014), which unfortunately doesn't work with the Aurelia Kendo Bridge. Therefore, I have to initialize the KendoGrid myself. I am copying over code as follows into Aurelia's attached()
lifecycle method:
$("#grid").kendoGrid({
data: null,
dataSource: {
type: "odata",
transport: {
read: {
url: this.apiUrl,
dataType: "json"
},
parameterMap: function (options, operation) {
var paramMap = kendo.data.transports.odata.parameterMap(options);
if (paramMap.$inlinecount) {
if (paramMap.$inlinecount == "allpages") {
paramMap.$count = true;
}
delete paramMap.$inlinecount;
}
if (paramMap.$filter) {
paramMap.$filter = paramMap.$filter.replace(/substringof\((.+),(.*?)\)/, "contains($2,$1)");
}
return paramMap;
}
},
schema: {
data: function (data) {
return data.value;
},
total: function (data) {
return data["@odata.count"];
},
model: {
fields: {
Name: { type: "string" }
}
}
},
pageSize: this.gridPageSize,
serverPaging: true,
serverFiltering: true,
serverSorting: true,
sort: { field: "Name", dir: "asc" }
},
dataBound: function (e) {
var body = this.element.find("tbody")[0];
if (body) {
// TODO: Figure out how to do this in Aurelia
//ko.cleanNode(body);
//ko.applyBindings(ko.dataFor(body), body);
}
},
filterable: true,
sortable: {
allowUnsort: false
},
pageable: {
refresh: true
},
scrollable: false,
columns: [{
field: "Name",
title: this.translations.columns.name,
filterable: true
}, {
field: "Id",
title: " ",
template:
'<div class="btn-group">' +
'<button type="button" click.delegate="edit(#=Id#)" class="btn btn-default btn-xs">' + this.translations.edit + '</button>' +
'<button type="button" click.delegate="remove(#=Id#)" class="btn btn-danger btn-xs">' + this.translations.delete + '</button>' +
'</div>',
attributes: { "class": "text-center" },
filterable: false,
width: 120
}]
});
So for the grid's dataBound
function, I want Aurelia to refresh it's bindings (to pickup the click bindings on the buttons in each row).