knockout.js Demo


' ].join('') }); $(function () { var Controller = function (widgets) { var self = this; this.widgets = ko.observableArray(widgets); this.add_new_widget = function () { this.widgets.push({ x: 0, y: 0, width: Math.floor(1 + 3 * Math.random()), height: Math.floor(1 + 3 * Math.random()), auto_position: true }); }; this.delete_widget = function (item) { self.widgets.remove(item); }; }; var widgets = [ {x: 0, y: 0, width: 2, height: 2}, {x: 2, y: 0, width: 4, height: 2}, {x: 6, y: 0, width: 2, height: 4}, {x: 1, y: 2, width: 4, height: 2} ]; var controller = new Controller(widgets); ko.applyBindings(controller); });