在 Vista Gadget 中使用 Javascript 获取列表数据

Getting List data using Javascript in a Vista Gadget

本文关键字:Javascript 获取 列表 数据 Vista Gadget      更新时间:2023-09-26

我正在尝试使用 Web 服务将共享点列表的所有列表项放入 Windows 7 小工具中,但我不确定如何做到这一点,

我在谷歌上找到此代码没有任何解释,所以我不知道如何使用此代码获取列表数据,然后显示在Windows小工具中。

谁能引导我到正确的方向?

小工具.xml

    <?xml version="1.0" encoding="utf-8" ?>
<gadget>
  <name>HelloGadget</name>
  <version>1.0.0.0</version>
  <description>Hello World Gadget.</description>
  <hosts>
    <host name="sidebar">
      <base type="HTML" apiVersion="1.0.0" src="first.html" />
      <permissions>Full</permissions>
      <platform minPlatformVersion="1.0" />
    </host>
  </hosts>
</gadget>

首先.html

    <html>
<script>
//----------------- resizes the gadget display surface
function DoInit() {
    document.body.style.width = 90;
    document.body.style.height= 55;
    document.body.style.margin=0;
}
    $(document).ready(function() 
{
    var soapEnv =
        "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> 
            <soapenv:Body> 
                 <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> 
                    <listName>ListName</listName> 
                    <viewFields> 
                        <ViewFields> 
                           <FieldRef Name='Title' /> 
                       </ViewFields> 
                    </viewFields> 
                </GetListItems> 
            </soapenv:Body> 
        </soapenv:Envelope>";
    $.ajax({
        url: "http://my_site/_vti_bin/lists.asmx",
        type: "POST",
        dataType: "xml",
        data: soapEnv,
        complete: processResult,
        contentType: "text/xml; charset="utf-8""
    });
});
function processResult(xData, status) {
    $(xData.responseXML).find("z':row").each(function() {
        alert($(this).attr("ows_Title"));
    });
}
</script>
<body onload="DoInit();">
<table border="5"><tr><td><center><i>Hello World!</i></center></td></tr></table>
<div id = "clickit"> <button type="button" onclick="" >Click Me!</button> </div>
</body>
</html>

干杯

我们都熟悉SQL。 有一个名为SPSQL的新jQuery库。 这真的很酷,因为您可以使用SQL语法查询SharePoint。 只需添加适当的库,您就可以开始了。 请参阅下面的示例和此处的文章。

要获取项目,只需执行以下操作:

var result = SPSql.parseSQL('SELECT MyList.Field FROM MyList WHERE MyList.ID > 10 ORDER BY  MyList.ID DESC');

现在可以处理所有结果行:

for (var row = 0; row < result.length; row++) {
   for (var column in result[row])
      alert( column + ": " + result[row][column] );
 }