JSlink删除字段值中的字符 [英] JSlink to remove characters in field value

查看:80
本文介绍了JSlink删除字段值中的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SharePoint列表中,我有一个名为"Steps"的查找列。它有一系列数字。

In a SharePoint list I have a look up column that is named "Steps" and it has a sequence of numbers.

我想要做的是从数字序列中删除一个字符。在下面的示例中,您可以看到我想删除数字后面的字母。需要专门使用JSLINK。

但是找不到完整的代码示例

What I am wanting to do is remove a character from the sequence of numbers. In my example below you can see I want to remove the letters after the numbers. Need to use JSLINK specifically.
Just cannot find an exact example of code on how this is done

示例:

(当前)

步骤

1a

1b

2a

2b

Steps
1a
1b
2a
2b

(所需)

步骤

1

1
$
2

2

Steps
1
1
2
2

推荐答案

以下代码摘录供您参考:

Following code snippet for your reference:

<script type="text/javascript">
(function () {	 
    var overrideCtx = {};
    overrideCtx.Templates = {};
    overrideCtx.Templates.Fields = {
        'Steps': { 'View': RemoveLastCharacter}
    };
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();
 
function RemoveLastCharacter(ctx) {
    console.log(ctx.CurrentItem["Steps"]);
    ctx.CurrentItem["Steps"][0].lookupValue=ctx.CurrentItem["Steps"][0].lookupValue.substring(0, ctx.CurrentItem["Steps"][0].lookupValue.length - 1);
    return "<a href='http://sp/sites/dev/Lists/RestTest/DispForm.aspx?ID="+ctx.CurrentItem["Steps"][0].lookupId+"'>"+ctx.CurrentItem["Steps"][0].lookupValue+"</a>"; 
    }
</script>

在RemoveLastCharacter函数中,它返回一个指向查找列表显示表单的超链接,将此显示形式的url更改为你的工作。在我的演示中,我从名为"RestTest"的列表中查找值,这是原始渲染:

In RemoveLastCharacter function, it is returning a hyperlink to the lookup list display form, change this display form url with yours to make it work. In my demo, I lookup the value from a list named "RestTest", this is the original rendering:

这是转换后的渲染:

谢谢

最好的问候


这篇关于JSlink删除字段值中的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆