如何创建仅使用客户端javascript的sharepoint数据表单web部件

     2022-03-24     723

关键词:

With jQuery and SPServices, we have very powerful tools for accessing and manipulating Sharepoint data and precisiely contolling the presentation, entirely from the client side. But such solutions generally need to be either hard-coded into pages or require cumbersome content editor pastes or includes. The advantage of packaging a solution as a web part is that it is a breeze to drop it anywhere on the site. Using the technique below you can package up a purely HTML/JavaScript solution as a web part, combining the benefits of both.

1. Create the HTML/JS content that you would like to turn into a web part in the manner you are most comfortable with
2. Create a dummy page in the site to initially hold our xslt
3. Open site in Sharepoint Designer
4. Find the page created in step 2, detach it from the page layout (by right clicking it), and open it for editing.
5. Place your cursor before the closing < /ContentTemplate > or closing < /asp:Content > tag
6. Paste the code in the source block below.
7. Find
Title="DataView 1"
in the code you pasted and replace it with
Title="MoreUsefulWebPartName"
8. Replace the contents between the opening and closing ![CDATA tags with the HTML and/or JavaScript you created in step 1
9. Select all of the new code, starting with and including the opening WebPartPages:DataFormWebPart tag and ending with and including the closing /WebPartPages:DataFormWebPart tag
10. Switch from code view to designer view. You may ignore any warning you see about missing data sources.
11. Click the web part tab
12. In the "Save Web part" section, select the manner in which you would like to save the new web part.
13. Give the web part a useful name
14. Once you make the new web part available in the web part gallery, users may now add your javascript solution to any page as they would any other web part.
  1. <WebPartPages:DataFormWebPart runat="server" IsIncluded="True" AsyncRefresh="True" FrameType="None" NoDefaultStyle="TRUE" ViewFlag="8" Title="DataView 1" PageType="PAGE_NORMALVIEW" __markuptype="vsattributemarkup" __WebPartId="{231F0ACE-32B2-4179-AE6B-07242197C9EE}" id="g_231f0ace_32b2_4179_ae6b_07242197c9ee">
  2. <DataSources></DataSources>
  3. <datafields/>
  4. <XSL>
  5. <xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cmswrt="http://schemas.microsoft.com/WebPart/v3/Publishing/runtime" exclude-result-prefixes="xsl cmswrt x" >
  6. <xsl:import href="/Style Library/XSL Style Sheets/Header.xsl" />
  7. <xsl:import href="/Style Library/XSL Style Sheets/ItemStyle.xsl" />
  8. <xsl:import href="/Style Library/XSL Style Sheets/ContentQueryMain.xsl" />
  9. <xsl:template match="/">
  10. <xsl:text disable-output-escaping="yes">
  11. <![CDATA[
  12. <script type="text/javascript">
  13. alert("you can use javascript");
  14. </script>
  15. <strong>HTML Content</strong>
  16. ]]>
  17. </xsl:text>
  18. </xsl:template>
  19. </xsl:stylesheet>
  20. </XSL>
  21. </WebPartPages:DataFormWebPart>

如何仅使用客户端 JavaScript 正确签署对 Amazon 的 ItemLookup 的 GET 请求?

】如何仅使用客户端JavaScript正确签署对Amazon的ItemLookup的GET请求?【英文标题】:HowtoproperlysignaGETrequesttoAmazon\'sItemLookupusingclient-sideJavaScriptonly?【发布时间】:2014-04-3012:32:43【问题描述】:这是我目前所拥有的:functionsha256(stringTo... 查看详情

您如何仅通过 Javascript 读取 RTMP 流?

】您如何仅通过Javascript读取RTMP流?【英文标题】:HowdoyoureadanRTMPstreamthroughJavascriptonly?【发布时间】:2011-08-1519:07:18【问题描述】:我们想在不支持Flash(iOS等)的移动平台上使用RTMP数据流(不是视频)。由于Java也不是某些手... 查看详情

如何使用 JavaScript 在客户端创建用于存储的文件?

】如何使用JavaScript在客户端创建用于存储的文件?【英文标题】:HowcanIcreateafileforstorageontheclientsidewithJavaScript?【发布时间】:2010-10-1618:05:40【问题描述】:我需要创建一个临时文件来在客户端存储用户设置。是否可以使用JavaScr... 查看详情

仅使用 HTML/JavaScript 创建购物车

】仅使用HTML/JavaScript创建购物车【英文标题】:CreatingaShoppingCartusingonlyHTML/JavaScript【发布时间】:2013-04-2400:34:51【问题描述】:我不知道该怎么做才能完成这个项目。我需要创建一个只使用一个HTML页面的购物车。我已经设置了... 查看详情

如何仅使用 JavaScript 正确读取 json 文件 [重复]

】如何仅使用JavaScript正确读取json文件[重复]【英文标题】:HowtoreadjsonfilecorrectlyusingonlyJavaScript[duplicate]【发布时间】:2019-10-2716:46:47【问题描述】:我需要创建HTML选择器并从JSON中获取它们的值,我创建了JSON并尝试通过在html文... 查看详情

仅使用javascript检查由javascript创建的元素是不是存在[重复]

】仅使用javascript检查由javascript创建的元素是不是存在[重复]【英文标题】:Checkingifanelementcreatedbyjavascriptexistsusingonlyjavascript[duplicate]仅使用javascript检查由javascript创建的元素是否存在[重复]【发布时间】:2014-11-2220:22:44【问题描... 查看详情

如何仅使用 javascript 将图像转换为字节数组以将图像存储在 sql server 上?

】如何仅使用javascript将图像转换为字节数组以将图像存储在sqlserver上?【英文标题】:Howtoconvertimagetobytearrayusingjavascriptonlytostoreimageonsqlserver?【发布时间】:2012-03-0418:16:01【问题描述】:我正在努力使用客户端脚本将图像转换为... 查看详情

如何仅使用 CSS 创建淡入/淡出效果?

...出agsin。DOM元素调用和效果应该在CSS或CSS3中。我不能使用javascript和Jqu 查看详情

javascript使用仅限javascript创建无限下拉列表框(代码片段)

查看详情

如何仅使用 JavaScript 定位 Internet Explorer 11?

】如何仅使用JavaScript定位InternetExplorer11?【英文标题】:HowcanItargetonlyInternetExplorer11withJavaScript?【发布时间】:2013-07-0102:33:30【问题描述】:使用JavaScript仅针对IE11最不容易出错的方法是什么?注意:这实际上应该只用于分析或... 查看详情

如何使用 OAuth 2.0 实现 Web 小部件

...个Web小部件来显示来自我的网站的信息。该小部件将使用JavaScript包含在客户的网站HTML中,并且应该仅可用于我的客户--在我的网站上注册的网站。小部件中的信息应特定于当前正在访问客户网站的用户。因此,我需要对客户端... 查看详情

如何使用 JavaScript 仅加载 jpg 的一部分 [重复]

】如何使用JavaScript仅加载jpg的一部分[重复]【英文标题】:HowdoIloadonlyapartofjpgwithJavaScript[duplicate]【发布时间】:2015-05-2810:48:15【问题描述】:我正在寻找一种仅加载jpg一部分的方法。我尝试了XMLHttpRequest但我无法弄清楚。request.o... 查看详情

如何以编程方式创建用户可以下载的 Javascript 客户端文件? [复制]

】如何以编程方式创建用户可以下载的Javascript客户端文件?[复制]【英文标题】:HowtoprogrammaticallycreateaclientsidefileinJavascriptthatcanbedownloadedbytheuser?[duplicate]【发布时间】:2013-02-2708:32:52【问题描述】:我想尝试创建一个Javascript应... 查看详情

如何使用 VueJS 或仅使用 javascript 在多维数组中搜索

】如何使用VueJS或仅使用javascript在多维数组中搜索【英文标题】:HowtosearchinamultidimensionalarrayusingVueJSorjustjavascript【发布时间】:2017-10-2401:26:00【问题描述】:我正在做一个Vue项目,我只是VueJS的新手,我的问题是当我输入一个值... 查看详情

PayPal 结帐:不允许仅使用客户 ID 创建订单/订阅

...但任何人都可以轻松创建订阅,因为PayPal需要的只是公共客户端ID。这旨在允许(主要) 查看详情

如何仅使用 javascript 获取特定 div/form 的所有子输入?

】如何仅使用javascript获取特定div/form的所有子输入?【英文标题】:Howtograballchildinputsofaspecifcdiv/formusingjustjavascript?【发布时间】:2019-01-0804:18:39【问题描述】:我看到了类似的帖子here,但是我想使用javascript做类似的事情。基本... 查看详情

如何在客户端 javascript 中使用 Grafana Http API

】如何在客户端javascript中使用GrafanaHttpAPI【英文标题】:HowtouseGrafanaHttpAPIwithclient-sidejavascript【发布时间】:2016-03-0617:16:56【问题描述】:是否可以将GrafanaHttpAPI与客户端javascript一起使用?我从获取已创建仪表板的json的最基本知... 查看详情

仅使用 Javascript 显示/隐藏单击按钮的密码

】仅使用Javascript显示/隐藏单击按钮的密码【英文标题】:Show/hidepasswordonClickofbuttonusingJavascriptonly【发布时间】:2015-09-2208:22:08【问题描述】:我想在仅使用Javascript单击眼睛图标时创建密码切换功能。我已经为它编写了代码,但... 查看详情