BorisMoore/jsviews — Issue #34: Get values from array with data-to
Author: dervalp
Created: 2012-01-26 14:59:05+00:00
State: open

I try to use the link function with jsView to update the value of an array.

Here is the javascript (I am using backbone.js so the this.el is the current html element for the view):

that.viewModel = new Role();
that.viewModel.ModuleAccessList = [];
_.each(col.toJSON(), function (obj) { //col is a backbone collection that I convert to an json array with the toJSON()
that.viewModel.ModuleAccessList.push({ Module: obj, Access: "" });
});
var content = $("#AddRoleTemplate").render(this.viewModel);
$(this.el).html(content);
$(this.el).link(this.viewModel);

And the HTML:

{{#each ModuleAccessList}}

{{=Module.Name}}

none

readonly

full

{{/each}}

The value of the viewModel updates like :

ModuleAccessList[1].Access = "readonly" where ModuleAccessList[1].Access is a field.

Is there anyway to update the array directly with data-to and link ?