以后不可能使用 $(this) 有什么选择?
Later Usage of $(this) not possible what is the alternative?
我已经得到了这段被剪掉的小代码:
$(document).ready(function () {
$('td').each(function(index) {
thisValue = ""; //Variable leeren
//alert(index + ': ' + $(this).attr("id"));
currentField = $(this).attr("tid");
//alert (currentField);
currentID = $(this).attr("ftn");
//alert (currentID);
$SP().list(TableName).get({
fields: currentField,
where:"ID = "+currentID
},function getData(row) {
console.log (row[0].getAttribute(currentField) *1);
thisValue = (row[0].getAttribute(currentField) *1);
$(this).text(thisValue); // Wert der Listenzelle in die HTML Tabelle schreiben
})
});
它工作正常,如果我执行 console.log,每个搜索到的单元格元素的值都会显示在控制台中。但实际上我无法将这些值带入我认为是因为 $(this) 不再 "connected" 到我认为 html 页面中的表格单元格。
这是我的 HTML 结构:
<div class="uk-panel uk-panel-box uk-panel-box-muted">
<h4>Product 1</h4>
<table class="uk-table uk-table-hover uk-table-striped uk-table-condensed">
<tr><th>Service Requests:</th> <td tid="product1" ftn="1" id="sr_acvl">NULL</td></tr>
<tr><th>ITSM Tickets:</th> <td tid="product1" ftn="2" id="tt_acvl">NULL</td></tr>
<tr><th>E-Mails:</th> <td tid="product1" ftn="3" id="em_acvl">NULL</td></tr>
<tr><th>Anrufe:</th> <td tid="product1" ftn="4" id="ca_acvl">NULL</td></tr>
<tr><th>Skype & Other:</th> <td tid="product1" ftn="5" id="sk_acvl">NULL</td></tr>
</table>
</div>
你怎么看?
我认为这只是一件小聪明的事情,但我还没有看到任何解决方案...
顺便说一句。我从这里使用 sharepointplus:
http://aymkdn.github.io/SharepointPlus/symbols/$SP%28%29.list.html
亲切的问候
接近
只需将上下文引用存储在一个变量中供以后使用:
$(document).ready(function () {
$('td').each(function(index) {
var self = $(this); // <----- this is the key
thisValue = "";
currentField = self.attr("tid");
currentID = self.attr("ftn");
$SP().list(TableName).get({
fields: currentField,
where:"ID = "+currentID
},function getData(row) {
console.log (row[0].getAttribute(currentField) *1);
thisValue = (row[0].getAttribute(currentField) *1);
self.text(thisValue);
})
});
我已经得到了这段被剪掉的小代码:
$(document).ready(function () {
$('td').each(function(index) {
thisValue = ""; //Variable leeren
//alert(index + ': ' + $(this).attr("id"));
currentField = $(this).attr("tid");
//alert (currentField);
currentID = $(this).attr("ftn");
//alert (currentID);
$SP().list(TableName).get({
fields: currentField,
where:"ID = "+currentID
},function getData(row) {
console.log (row[0].getAttribute(currentField) *1);
thisValue = (row[0].getAttribute(currentField) *1);
$(this).text(thisValue); // Wert der Listenzelle in die HTML Tabelle schreiben
})
});
它工作正常,如果我执行 console.log,每个搜索到的单元格元素的值都会显示在控制台中。但实际上我无法将这些值带入我认为是因为 $(this) 不再 "connected" 到我认为 html 页面中的表格单元格。 这是我的 HTML 结构:
<div class="uk-panel uk-panel-box uk-panel-box-muted">
<h4>Product 1</h4>
<table class="uk-table uk-table-hover uk-table-striped uk-table-condensed">
<tr><th>Service Requests:</th> <td tid="product1" ftn="1" id="sr_acvl">NULL</td></tr>
<tr><th>ITSM Tickets:</th> <td tid="product1" ftn="2" id="tt_acvl">NULL</td></tr>
<tr><th>E-Mails:</th> <td tid="product1" ftn="3" id="em_acvl">NULL</td></tr>
<tr><th>Anrufe:</th> <td tid="product1" ftn="4" id="ca_acvl">NULL</td></tr>
<tr><th>Skype & Other:</th> <td tid="product1" ftn="5" id="sk_acvl">NULL</td></tr>
</table>
</div>
你怎么看? 我认为这只是一件小聪明的事情,但我还没有看到任何解决方案...
顺便说一句。我从这里使用 sharepointplus: http://aymkdn.github.io/SharepointPlus/symbols/$SP%28%29.list.html
亲切的问候 接近
只需将上下文引用存储在一个变量中供以后使用:
$(document).ready(function () {
$('td').each(function(index) {
var self = $(this); // <----- this is the key
thisValue = "";
currentField = self.attr("tid");
currentID = self.attr("ftn");
$SP().list(TableName).get({
fields: currentField,
where:"ID = "+currentID
},function getData(row) {
console.log (row[0].getAttribute(currentField) *1);
thisValue = (row[0].getAttribute(currentField) *1);
self.text(thisValue);
})
});