zoukankan      html  css  js  c++  java
  • SharePoint 2013 字段属性之JSLink 转载来源(http://www.cnblogs.com/jianyus/p/3544482.html)

    在SharePoint 2013中,SPField新增加了一个属性是JSLink,使用客户端脚本修改字段前台展示,我们可以用很多方法修改这个脚本的引用,然后来修改脚本,下面,我们举一个简单的例子。

    具体过程

      A. 创建一个栏 -> B.使用工具修改JSLink的默认值 -> C.写JSLink的脚本

      1、在新列表,创建一个字段PicUrl,如下图:

    clip_image001

      2、在layouts下新建一个文件夹,里面放JSLink.js(名字可以随便取);

    clip_image002

      3、使用SharePoint Manager 2013,找到相应字段修改其JSLink属性,如下图:

    clip_image003

      4、JSLink.js内容及介绍,如下图:

      重点就是下面的JS如何写,模板建议大家不要动,重写下面画圈的方法即可。注意方框部分里面是字段名称,不要写错,就可以。

      个人试想这里面还可以写复杂一点的脚本,但是没有试过,待以后需要的时候尝试一下,留个博客,方便以后查找,呵呵。

    clip_image004

    复制代码
     1 // Create a namespace for our functions so we don't collide with anything else
     2 var PicUrlReWrite= PicUrlReWrite|| {}; 
     3 
     4 // Create a function for customizing the Field Rendering of our fields
     5 PicUrlReWrite.CustomizeFieldRendering = function ()
     6 {
     7     var fieldJsLinkOverride = {};
     8     fieldJsLinkOverride.Templates = {};
     9     fieldJsLinkOverride.Templates.Fields =
    10     {
    11         // Make sure the Priority field view gets hooked up to the GetPriorityFieldIcon method defined below
    12         'PicUrl': { 'View': PicUrlReWrite.ReWriteFieldValue }
    13     }; 
    14 
    15     // Register the rendering template
    16     SPClientTemplates.TemplateManager.RegisterTemplateOverrides(fieldJsLinkOverride);
    17 }; 
    18 
    19 // Create a function for getting the Priority Field Icon value (called from the first method)
    20 PicUrlReWrite.ReWriteFieldValue = function (ctx) {
    21     var PicUrl = ctx.CurrentItem.PicUrl;
    22 
    23     // In the following section we simply determine what the rendered html output should be. In my case I'm setting an icon. 
    24 
    25     return "<img src='"+ PicUrl +"' width='700' height='300'></img>";
    26 
    27 }; 
    28 
    29 // Call the function. 
    30 
    31 // We could've used a self-executing function as well but I think this simplifies the example
    32 
    33 PicUrlReWrite.CustomizeFieldRendering();
    复制代码

      5、新建一条数据,如下图所示:

    clip_image005

      6、默认展示效果,如下图:

    clip_image006

      7、查看修改JSLink后展示,如下图:

    clip_image007

      本文是参考如下博客做的测试,测试过程中遇到点问题,想了很久又查了资料,才发现js应该怎么写,所以拿出来说一下,如有需要,参考后面链接。

      附链接

      http://blog.csdn.net/abrahamcheng/article/details/12090265

  • 相关阅读:
    MySQL分页实现
    一周自学动态站点设计
    hdu 1233(还是畅通project)(prime算法,克鲁斯卡尔算法)(并查集,最小生成树)
    windows下使用lighttpd+php(fastcgi)+mysql
    Thinkpad E431 解决无线网卡无法开启
    创建与删除索引
    IC芯片
    Linux IPC(Inter-Process Communication,进程间通信)之管道学习
    POJ 3090 Visible Lattice Points 欧拉函数
    多区域显示(3)
  • 原文地址:https://www.cnblogs.com/TNSSTAR/p/3601443.html
Copyright © 2011-2022 走看看