【问题标题】:jquery datatable how to parse and add row from MVCjquery datatable如何从MVC解析和添加行
【发布时间】:2012-07-02 12:50:38
【问题描述】:

好的,我有以下内容

function AddSpellRow() {
    var row = $('.tbl_spells').dataTable().fnGetData(0);
    $('.tbl_spells').dataTable().fnAddData(row);
}

添加这一行

<tr class="odd">

   <td class="">    
     <input data-val="true" data-val-number="The field Id must be a number." data-val-required="The Id field is required." id="Spells_0__Id" name="Spells[0].Id" type="hidden" value="4"> 

     <select data-val="true" data-val-number="The field Id must be a number." data-val-required="The Id field is required." id="Spells_0__Spell_Id" name="Spells[0].Spell.Id" class="valid">
       <option value="">---Select --</option> 
       <option value="1">Rains</option> 
     </select>

   </td>

   <td class="">
    <input data-val="true" data-val-number="The field PriestLevel must be a number." data-val-required="The PriestLevel field is required." id="Spells_0__PriestLevel" name="Spells[0].PriestLevel" type="text" value="10" class="valid">
   </td>

</tr>

如何用 [#of rows] 和 underscorenumber of rowsunderscore 更改 [0] 和 underscore0underscore ?

我还需要 type="hidden" value="4" 和 type="hidden" value="0"

我尝试在行上替换,但它不喜欢它。

【问题讨论】:

    标签: javascript jquery asp.net-mvc datatables


    【解决方案1】:

    我不得不使用 fnAddData

        var otable = $('.tbl_spells').dataTable();
        var row = otable.fnGetData(0),
        row_count = otable.fnGetData().length;
    
        var addId = otable.fnAddData(row);
        var newRow = otable.fnSettings().aoData[addId[0]].nTr;
    
        var theNode =  $(newRow.cells[0])  ;
        $(theNode[0].children[0]).attr('id', 'Spells_' + row_count + '__Id');
        $(theNode[0].children[0]).attr('name', 'Spells[' + row_count + '].Id');
        $(theNode[0].children[0]).attr('value', 0 );
    
        $(theNode[0].children[1]).attr('id', 'Spells_' + row_count + '__Spell_Id');
        $(theNode[0].children[1]).attr('name', 'Spells[' + row_count + '].Spell.Id');
    
        theNode = $(newRow.cells[1]);
        $(theNode[0].children[0]).attr('id', 'Spells_' + row_count + '__PriestLevel');
        $(theNode[0].children[0]).attr('name', 'Spells[' + row_count + '].PriestLevel');
    

    【讨论】:

      猜你喜欢
      • 2019-11-15
      • 2014-05-20
      • 1970-01-01
      • 1970-01-01
      • 2018-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-18
      相关资源
      最近更新 更多