简体   繁体   English

在按钮单击时以角度创建表格中的文本框

[英]Create text boxes in table in angular on button click

I want to be able to click a button on a table and update the row information. 我希望能够单击表上的按钮并更新行信息。 I have the back-end all set up to do this. 我有后端所有设置来做到这一点。 I am just having trouble being able to get at the table generated by angular. 我只是无法进入由角度生成的表格。 Here is my html template: 这是我的html模板:

<br />
<table id="recordTable" border="1px">
    <tr><td ng-repeat="column in columns"><strong>{{column.column_name}}</strong></td>          </tr>
    <tr ng-repeat="record in records">
        <td ng-repeat="cell in record.cells">  {{cell}}  </td>
        <td><button ng-click="delete($index)">Delete</button></td>
        <td><button ng-click="update($index)">Update</button></td>
    </tr>
</table>
<br />

When I call the function update($index) , I would like to be able to turn the text that is currently filled with {{column.column_name}} into a text input with the {{column.column_name}} as the default text. 当我调用函数update($index) ,我希望能够将当前用{{column.column_name}}填充的文本转换为文本输入,并将{{column.column_name}}作为默认文本。 I could not find anything in the Docs for this. 我在文档中找不到任何内容。 Any thoughts? 有什么想法吗?

I've made a slight change to the record.cells array, now it is [{value : 'Value1'},{value : 'Value2'}] 我对record.cells数组稍作修改,现在是[{value : 'Value1'},{value : 'Value2'}]

<table id="recordTable" border="1px">
    <tr>
        <td ng-repeat="column in columns">
            <strong>{{column.column_name}}</strong>
        </td>
    </tr>
    <tr ng-repeat="record in records">
        <td ng-repeat="cell in record.cells">
          <span ng-show="mode != 'edit'">{{cell.value}}</span>
          <input ng-show="mode == 'edit'" ng-model="cell.value" />
        </td>
        <td><button ng-click="delete($index)">Delete</button></td>
        <td>
          <button ng-show="mode != 'edit'" ng-click="mode = 'edit'">Update</button>
          <button ng-show="mode == 'edit'" ng-click="mode = null">Save</button>
        </td>
    </tr>
</table>

Demo: Plunker 演示: Plunker

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM