Knockout.js 数据绑定以移动表的列

Knockout.js 数据绑定以移动表的列,knockout.js,Knockout.js,我使用knockout动态地将行和列添加到表中,但我还需要通过拖放对列重新排序 视图: 使用dragtable.js解决了这个问题 您可能想签出淘汰排序表 <table id="gridTable"> <tr data-bind="foreach: activeColumns"> <th data-bind="text: display"></th> </tr> <tbody id="s

我使用knockout动态地将行和列添加到表中,但我还需要通过拖放对列重新排序

视图:


使用dragtable.js解决了这个问题


您可能想签出淘汰排序表
    <table id="gridTable">
    <tr data-bind="foreach: activeColumns">
      <th data-bind="text: display"></th>
    </tr>
    <tbody id="sortable" data-bind="foreach: rows">
     <tr data-bind="foreach: $root.activeColumns">
         <td>
            <span  data-bind="visible: readonly, text: $parent[property]"></span>
            <input data-bind="visible: !readonly, value: $parent[property]"/>
          </td>
</tr>
</tbody>
rows: ko.observableArray([
new Person(1, "Bob", 44),
new Person(2, "Ted", 22),
new Person(3, "Jane", 55),
new Person(4, "Sue", 11)
]),
activeColumns: ko.observableArray([{property: 'id', display: 'ID', readonly: true},
{property: 'name', display: 'Name', readonly: false}, {property: 'age', display: 'Age',
readonly: false}]),
addColumn: function() {
    var newProperty = this.newAttribute();
    var newProperty1= this.selectedCategory();
    this.activeColumns.push({property: newProperty, display: newProperty, readonly: 
 false});
    ko.utils.arrayForEach(this.rows(), function(row) {
        if (!row[newProperty]) {
        row[newProperty] = ko.observable();
        }
    });