简体   繁体   English

替换仅适用于前2个列表项

[英]Replace only works on first 2 list items

I am using SharePoint 2013 in the cloud. 我正在云中使用SharePoint 2013。 I have a page with a list WebPart that displays a view I setup that groups list items. 我有一个带有列表WebPart的页面,该页面显示了我设置的将列表项分组的视图。 This creates an expandable tree view. 这将创建一个可扩展的树视图。

I am trying to remove the preceeding column name from each of the list items. 我正在尝试从每个列表项中删除前面的列名。 The column name is Group , so each list items is displayed as Group : Item . 列名是Group ,因此每个列表项都显示为Group:Item The column name and the list item value are both wrapped in links, so I need to remove the Group portion and the : that is left in the middle. 列名和列表项值都包装在链接中,因此我需要删除Group部分和中间的:。

I am using the following code: 我正在使用以下代码:

$("a:contains('Group')").closest("td").html( 
    function(index, text) {
        return text.replace(' : ', ' ');
    }
);
$("a:contains('Group')").html(
    function(index, text) {
        if(text.indexOf('Info') < 1) {
            return text.replace(/Group/, '&nbsp;');
        }
    }
);

The Group portion works fine. 组部分工作正常。

I have used this code on another site with a similar page and it removes all the column names and colons. 我在另一个具有类似页面的站点上使用了此代码,它删除了所有列名和冒号。 When I do it on this page, it stops removing the colons after the 2nd list item. 当我在此页面上执行此操作时,它将停止删除第二个列表项之后的冒号。 For example 例如

Group : Item 1
Group : Item 2
Group : Item 3
Group : Item 4

turns into 变成

Item 1
Item 2
: Item 3
: Item 4

After trying a few methods for removing the unwanted text, I decided to change the column name value from "Group" to "Area". 在尝试了几种删除不需要的文本的方法之后,我决定将列名值从“组”更改为“区域”。 Since the Page had "Group Info Wiki" on it and I was trying to prevent that "Group" text from changing, I had 由于页面上有“ Group Info Wiki”,并且我试图防止更改“ Group”文本,所以我不得不

if(text.indexOf('Info') < 1) {
      return text.replace(/Group/, '&nbsp;');
}

By removing the if statement part of the code, it fixed the problem. 通过删除代码的if语句部分,它解决了该问题。

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

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