【问题标题】:ajax.actionlink insertionmode insertafter for tableajax.actionlink 插入模式 insertafter 用于表
【发布时间】:2015-01-11 06:50:29
【问题描述】:

如果我有一个包含可变数量 <tr> 元素的表,

<table id="my_table">
 <!--there could be 1 tr or 3, don't know, server decides based on database-->
 <tr>
  <td>a</td>
  <td>b</td>
  <td>c</td>
 </tr>

</table>

我有一个Ajax.ActionlinkInsertionMode.InsertAfter,我想在其中插入一个新的&lt;tr&gt; 我是定位"my_table" 还是必须定位我拥有的最后一个&lt;tr&gt;

如果是后者,这意味着我必须为最后一个 &lt;tr&gt; 元素提供一个动态生成的 id 值,以便我可以访问那个,对吗?

有没有更简单的方法来做到这一点?还是我误解了插入后的工作方式?

【问题讨论】:

    标签: javascript html ajax asp.net-mvc


    【解决方案1】:

    您可以在表格末尾包含一个隐藏的 tr,然后使用 insertMode.Replace

    <table>
       <tr id='1'>
          <td>something</td>
       </tr>
       <tr id='replaceme' class='hidden'><tr>
    </table>
    

    不要忘记您的替换 html 应该包含另一个 &lt;tr id='replaceme'&gt;

    真的应该有一个insertionmode.append和prepend

    【讨论】:

    • 我是智障,谢谢你让我意识到我的慢...不敢相信我没有想到这个大声笑,谢谢你启发我
    • 我同意,我正在考虑追加
    • 只是在想,我认为我需要“ReplaceWith”来解决这个问题,因为 replace 替换了隐藏的 tr 元素内的所有内容,但是 ReplaceWith 替换了 tr 元素本身。如果我只替换隐藏 tr 内的内容,我不能在返回的部分视图中返回一个 tr,因为它将嵌套在主视图中的隐藏 tr 内……你跟着我吗?不确定我是否有道理
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-11
    • 2012-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多