这个骆驼子句怎么了

时间:2019-10-16 22:29:41

标签: javascript sharepoint-2013 caml

只需学习如何使用骆驼并遇到问题。我可以正确地执行两个不同的查询,但是当我将它们组合时,会收到一条错误消息。我查看了文档,但仍然不明白问题所在。

查询1:

   var specifier1 = "<Where><Eq><FieldRef Name='Requestor_x0020_Name' LookupId='True'/><Value Type='Lookup'>" +
                           "<UserID/></Value></Eq></Where>";

查询2:

   var specifier2 = "<Where><Eq><FieldRef Name='ID'/><Value Type='Text'>"+currentItemID+"</Value>"+
                           "</Eq></Where>";

组合查询:

   var specifier = "<Where><And><Eq><FieldRef Name='Requestor_x0020_Name' LookupId='True'/><Value Type='Lookup'>" +
                           "<UserID/></Value></Eq><And><Eq>"+
                           "<FieldRef Name='ID'/><Value Type='Text'>"+currentItemID+"</Value>"+
                           "</Eq></And></And></Where>";

合并查询出现的错误是:

Request Failed.One or more field types are not installed properly. Go to the list settings page to delete these fields.
undefined

设置字符串后,我有以下电话。当您具有AND条件时,可能需要不同吗?我的枚举器循环中的console.log似乎是失败的地方。错误消息似乎遵循6x:xxxxxx

   camlQuery.set_viewXml("<View><Query>"+specifier+"</Query></View>");
   var collListItems = list.getItems(camlQuery);
   ctx.load(collListItems);
   ctx.executeQueryAsync(
        function(){
            var enumerator = collListItems.getEnumerator();
            count = collListItems.get_count();
            while(enumerator.moveNext()){
                var item = enumerator.get_current();
                console.log("xxxxxID : " + item.get_id());
            }
            if (count == 0) {
                LockDownCells();
            }
        },
        function(sender,args){
             console.log("xxxxxxRequest Failed."+args.get_message() + "\n" + args.get_stackTrace());
        }
    );

2 个答案:

答案 0 :(得分:0)

尝试一下:

import React, { useState, useEffect } from 'react';
import { Button, Box, Grid } from 'grommet';
import { Add, Close } from 'grommet-icons';

import { Files } from '../Component/Files/Files';
import { ePub } from '../extension/ePub/ePub';

interface Props {}

export const FolderPage: React.FC<Props> = () => {
  const [state, setState] = useState([<Files openFileHandlers={[ePub]} />]);

  const newFolderPanel = () => setState(prev => prev.concat(<Files openFileHandlers={[ePub]} />));

  const removePanel = (panel: JSX.Element) => setState(prevState => prevState.filter(s => s !== panel));

  return (
    <div>
      <Box align="start" pad="xsmall">
        <Button icon={<Add />} label="New Folder Panel" onClick={newFolderPanel} primary />
      </Box>
      {state.map((s, index) => (
        <Grid key={index}>
          <Box align="end">
            <Button
              icon={<Close color="white" style={{ backgroundColor: 'red', borderRadius: '50%', padding: '.25rem' }} />}
              type="button"
              onClick={() => removePanel(s)}
            />
          </Box>
          {s}
        </Grid>
      ))}
    </div>
  );
};

答案 1 :(得分:0)

按如下所示修改代码。

<script type="text/javascript">
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', retrieveListItems);
function retrieveListItems(){
    var currentItemID=2;     
    var listTitle="CL1017"; 
    var specifier = "<Where><And>"+
                     "<Eq><FieldRef Name='Requestor_x0020_Name' LookupId='True'/><Value Type='Lookup'><UserID/></Value></Eq>"+
                     "<Eq><FieldRef Name='ID'/><Value Type='Text'>"+currentItemID+"</Value></Eq>"+
                     "</And></Where>";

    var ctx = new SP.ClientContext.get_current();
    var list = ctx.get_web().get_lists().getByTitle(listTitle);
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml("<View><Query>"+specifier+"</Query></View>");
    var collListItems = list.getItems(camlQuery);
    ctx.load(collListItems);
    ctx.executeQueryAsync(
        function(){
            var enumerator = collListItems.getEnumerator();
            count = collListItems.get_count();
            while(enumerator.moveNext()){
                var item = enumerator.get_current();
                console.log("xxxxxID : " + item.get_id());
            }
            if (count == 0) {
                //LockDownCells();
            }
        },
        function(sender,args){
             console.log("xxxxxxRequest Failed."+args.get_message() + "\n" + args.get_stackTrace());
        }
    );
}
</script>

如果您只想按商品ID查询列表商品,建议您使用下面的代码,我们不需要使用CAML查询。

<script type="text/javascript">
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', retrieveListItems);
function retrieveListItems(){
    var itemId=2;    
    var listTitle="CL1017";                          
    var ctx = new SP.ClientContext.get_current();
    var list = ctx.get_web().get_lists().getByTitle(listTitle);  
    var listItem = list.getItemById(itemId);
    ctx.load(listItem);
    ctx.executeQueryAsync(
        function(){
            console.log("xxxxxID : " + listItem.get_id());
        },
        function(sender,args){
             console.log("xxxxxxRequest Failed."+args.get_message() + "\n" + args.get_stackTrace());
        }
    );
}
</script>