[英]I am trying to highlight my table row on sharepoint if it matches anything in an array, why doesn't it work?
I have a table on Sharepoint and an array, I tried to compare them and highlight the ones that match but it doesn't work. 我在Sharepoint上有一张桌子和一个数组,我试图将它们进行比较并突出显示匹配的那些,但这是行不通的。 Please help!
请帮忙! The following code is coded in Javascript.
以下代码使用Javascript编码。 I have tried various ways and tweaked accordingly according to my findings all around the web but nothing seems to be able to resolve this issue.
我尝试了各种方法,并根据我在网络上的发现进行了相应的调整,但是似乎没有任何方法可以解决此问题。
//gets table
var oTable = document.getElementById('tablename');
//gets rows of table
var rowLength = oTable.rows.length;
//loops through rows
for (i = 0; i < rowLength; i++){
//gets cells of current row
var oCells = oTable.rows.item(i).cells;
//gets amount of cells of current row
var cellLength = oCells.length;
//loops through each cell in current row
for(var j = 0; j < cellLength; j++){
// get your cell info here
var cellVal = oCells.item(j).innerHTML;
console.log(cellVal);
var serverRelativeUrlOfMyFile = "https://Sharepointsite/Blacklist.txt";
$.ajax({
url: serverRelativeUrlOfMyFile,
type: "GET"
}).done(handler);
function handler(data){
//console.log(data);
var lines = data.split('\n');
for(var line = 0; line < lines.length; line++)
{
if (cellVal.includes(lines[line])){
oCells.item[j].style.background = "red";
}
}
}
}
}
Below's another way that I tried to match my table on Sharepoint with my array. 下面是我尝试将Sharepoint上的表与数组匹配的另一种方法。 It works partially - Only the last item in the array gets matched when I run through the array properly.
它部分起作用-当我正确运行数组时,只有数组中的最后一项才匹配。 I don't really understand so appreciate the people out there who can help!
我不太了解,所以感谢能帮助我的人! Thanks a lot in advance.
非常感谢。
(Additional Information!) I create my table on Sharepoint by generating a table using Javascript with the executeQueryAsync function to retrieve data from a Sharepoint list and then producing it out as a viewable HTML table. (其他信息!)我通过在Java上使用表和executeQueryAsync函数生成一个表以从Sharepoint列表中检索数据,然后将其生成为可查看的HTML表,从而在Sharepoint上创建表。
var serverRelativeUrlOfMyFile = "https://Sharepointsite/SoftwaresBlacklist.txt";
$.ajax({
url: serverRelativeUrlOfMyFile,
type: "GET"
}).done(handler);
function handler(data){
//console.log(data);
var lines = data.split('\n');
for(var line = 0; line < lines.length; line++){
//var templines = lines;
//alert(lines[line]);
$("#tablename tr:contains('" + lines[line] + "')").css("background-color", "red");
}
}
I ran into something similar recently. 我最近遇到了类似的情况。 It came down to an issue of "scope" when referring to objects outside of the AJAX function.
当引用AJAX函数之外的对象时,它归结为“范围”问题。
Try something like this: (the new property named "theCells" and the line that starts with "this.theCells".) 尝试这样的事情:(名为“ theCells”的新属性以及以“ this.theCells”开头的行。)
$.ajax({
url: serverRelativeUrlOfMyFile,
theCells: oCells,
type: "GET"
}).done(handler);
function handler(data){
//console.log(data);
var lines = data.split('\n');
for(var line = 0; line < lines.length; line++)
{
if (cellVal.includes(lines[line])){
//oCells.item[j].style.background = "red";
this.theCells.item(j).style.background = "red";
}
}
}
Another note, "item" is a method, so should use (), not []. 另外请注意,“ item”是一种方法,因此应使用(),而不要使用[]。
this.theCells.item[j].style.background = "red";
this.theCells.item(j).style.background = "red";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.