【发布时间】:2021-02-15 02:07:52
【问题描述】:
我正在尝试向每个动态生成的行元素 (MatNr) 添加一个函数,以从我们的 SAP 系统中获取名称、可用部分和单位。
例如:
输入号码 = 464411
结果: 文章正文:“BATTERIE LI-Ionen AKKUPACK 3. 7V 800mAh”
单位 = ST
5 件可用
我可以添加新行,但从逻辑上讲,该函数始终指向第一行,因为名称都相同。我需要该函数“知道”它在哪一行,然后以某种方式使用行号调用该函数,还是我需要动态生成名称还是两者兼而有之??
请帮忙!
代码:
<div>
<table id="mattable">
<thead>
<tr>
<th>Menge</th>
<th>Einheit</th>
<th>Materialnummer</th>
<th>Material Text</th>
<th>Kommentar</th>
<th>Freibestand</th>
</tr>
</thead>
<tbody>
<tr>
<td style="width:100px">
@Html.EditorFor(model => model.Menge, new { htmlAttributes = new { style = "Width:80px", @class = "form-control" } })
</td>
<td style="width:70px">
@Html.EditorFor(model => model.Einheit, new { htmlAttributes = new { style = "Width:50px", @class = "form-control", @readonly = "true" } })
</td>
<td style="width:130px">
@Html.EditorFor(model => model.MatNr, new { htmlAttributes = new { style = "Width:110px", @class = "form-control", onblur = "getMat()" } })
</td>
<td style="width:300px">
@Html.EditorFor(model => model.MatTxt, new { htmlAttributes = new { style = "Width:300px", @class = "form-control"} })
</td>
<td style="width:220px">
@Html.EditorFor(model => model.Comment, new { htmlAttributes = new { style = "Width:200px", @class = "form-control" } })
</td>
<td style="width:100px">
@Html.EditorFor(model => model.Freibestand, new { htmlAttributes = new { style = "Width:90px", @class = "form-control", @readonly = "true" } })
</td>
<td> <input class="btnAdd btn btn-default" type="button" name="name" value="+" onclick="addrow()" /></td>
</tr>
</tbody>
</table>
<br />
<script type="text/jscript">
function addrow() {
var tbodyRowCount = "MatNr"+mattable.tBodies[0].rows.length+1;
var td1 = '<td style="width:100px">@Html.EditorFor(model => model.Menge, new { htmlAttributes = new { style = "Width:80px", @class = "form-control" } })</td>';
var td2 = '<td style="width:70px">@Html.EditorFor(model => model.Einheit, new { htmlAttributes = new { style = "Width:50px", @class = "form-control", @readonly = "true" } })</td>';
var td3 = '<td style="width:130px">@Html.EditorFor(model => model.MatNr, new { htmlAttributes = new { style = "Width:110px", @class = "form-control", onblur = "getMat()" } })</td>'
var td4 = '<td style="width:300px">@Html.EditorFor(model => model.MatTxt, new { htmlAttributes = new { style = "Width:300px", @class = "form-control", @readonly = "true" } })</td>';
var td5 = '<td style="width:220px">@Html.EditorFor(model => model.Comment, new { htmlAttributes = new { style = "Width:200px", @class = "form-control" } })</td>';
var td6 = '<td style="width:100px">@Html.EditorFor(model => model.Freibestand, new { htmlAttributes = new { style = "Width:90px", @class = "form-control", @readonly = "true" } })</td>';
var td7 = '<td> <input class="btnAdd btn btn-default" type="button" name="name" value="+" onclick="addrow()" /></td>'
$("#mattable > tbody").append('<tr>' + td1 + td2 + td3 + td4 + td5 + td6 + td7 + '</tr>');
}
function getMat() {
var text = $('#MatNr').val();
var url = "/Apps/GetMatInfos";
$.get(url, { MatNr: text }, function (data) {
$("#MatTxt").val(data[0]);
$("#Freibestand").val(data[1]);
$("#Einheit").val(data[2]);
})
}
</script>
</div>
【问题讨论】:
-
@Html.EditorFor是由 ASP.NET MVC 在服务器端生成的代码;它不适用于客户端代码。
标签: javascript html ajax asp.net-mvc