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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何创建仅使用客户端JavaScript的sharepoint数据表单web部件相关的知识,希望对你有一定的参考价值。

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的sharepoint数据表单web部件的主要内容,如果未能解决你的问题,请参考以下文章

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

如何仅使用 javascript 创建/添加新表行

仅使用 HTML/JavaScript 创建购物车

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

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

JQuery 插件,Javascript - 如何仅为 JQuery 插件全局变量或 json 对象创建并在函数级别更改此(变量、对象)