我可以将vlaues传递给execCrossDomainRequest()吗? [英] Can I pass vlaues to execCrossDomainRequest()?

查看:76
本文介绍了我可以将vlaues传递给execCrossDomainRequest()吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我在一个应用程序中工作,该应用程序根据用户在应用程序设置面板中输入的值来创建图表.现在,我可以使用console.log测试用户可以插入值,并且应用程序正在接收它.下一步是在我的应用中使用此值.为了那个原因 我创建了一些变量来保存值.其中两个值是列表的名称listName和子站点的名称subSiteName.我的想法是像这样将这些值传递给execCrossDomainRequest:

$.getScript(scriptbase +"SP.RequestExecutor.js",execCrossDomainRequest(listName,subSiteName));

然后使用它们来构建我的网址,如下所示:

函数execCrossDomainRequest(listName,subSiteName){            var executor =新的SP.RequestExecutor(appweburl);            executor.executeAsync({ "')/items?@target ='" + hostweburl +"/" + subSiteName +""',

但不起作用.我收到一个consol错误:"Uncaught ReferenceError:未定义SP"

如何将值传递给execCrossDomainRequest?

我粘贴了一部分代码,这样您可以得到更好的画面:

 $(document).ready(function(){
            hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl")));
            appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl")));

            var scriptbase = hostweburl +"/_layouts/15/";


            var listName = getQueryStringParameter('ListName');
            var subSiteName = getQueryStringParameter('SubSiteName');
            var xName = getQueryStringParameter('xName');
            var yName = getQueryStringParameter('yName');
            var chartLabel = getQueryStringParameter('chartLabel');


            console.log(listName,subSiteName,xName,yName,chartLabel);


            $ .getScript(scriptbase +"SP.RequestExecutor.js",execCrossDomainRequest(listName,subSiteName));
        });

        函数execCrossDomainRequest(listName,subSiteName){
            var executor =新的SP.RequestExecutor(appweburl);

            executor.executeAsync({
                url:appweburl +``/_api/SP.AppContextSite(@target)/web/lists/getbytitle('''+ listName +``')/items?@target ='" + hostweburl +"/"; + subSiteName +'",
                方法:"GET",
                标头:{"Accept":"application/json; odata = verbose" },
                成功:successHandler,
                错误:errorHandler
            });
        } 

谢谢您的帮助!

ReferenceError:未定义SP

解决方案

好,最近两天我一直在测试此代码,并且得到了一些改进.

现在,我可以将列表名称和子站点名称传递给url.剩下的问题是图表创建图表所需的值(x值和y值).

我正在尝试使用这些值,如下所示:

 


(结果).each(function(){ chartX.push(this.xValue); chartY.push(this.yValue); });

问题是我对两个变量(xValue和yValue)都未定义

如果我这样做:

 


(结果).each(function(){ console.log(xValue); console.log(yValue); //chartX.push(this.xValue); //chartY.push(this.yValue); });

我获得了xValues和yValues的期望值.

为什么当我使用'this'时会变得不确定?

xValues和yValue的类型为字符串.


Hello,

I am working in a app that create a chart based in values that the user enter in the app settings panel. Right now the user can insert the values and the app is receiving it, I tested with a console.log. The next step is use this values in my app. For that I created some variables to save the values. Two of these values are the name of a list, listName, and the name of a subsite, subSiteName. My idea is to pass these values to the execCrossDomainRequest like this:

$.getScript(scriptbase + "SP.RequestExecutor.js", execCrossDomainRequest(listName, subSiteName));

And then use them to build my url like this:

function execCrossDomainRequest(listName, subSiteName) {            var executor = new SP.RequestExecutor(appweburl);            executor.executeAsync({                url: appweburl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('" + listName + "')/items?@target='" + hostweburl + "/" + subSiteName + "'",

but is not working. I am getting a consol error: "Uncaught ReferenceError: SP is not defined" 

How can I pass values to the execCrossDomainRequest?

I paste a portion of the code so you can have a better picture: 

$(document).ready(function () {
            hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
            appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"));

            var scriptbase = hostweburl + "/_layouts/15/";


            var listName = getQueryStringParameter('ListName');
            var subSiteName = getQueryStringParameter('SubSiteName');
            var xName = getQueryStringParameter('xName');
            var yName = getQueryStringParameter('yName');
            var chartLabel = getQueryStringParameter('chartLabel');


            console.log(listName, subSiteName, xName, yName, chartLabel);


            $.getScript(scriptbase + "SP.RequestExecutor.js", execCrossDomainRequest(listName, subSiteName));
        });

        function execCrossDomainRequest(listName, subSiteName) {
            var executor = new SP.RequestExecutor(appweburl);

            executor.executeAsync({
                url: appweburl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('" + listName + "')/items?@target='" + hostweburl + "/" + subSiteName + "'",
                method: "GET",
                headers: { "Accept": "application/json; odata=verbose" },
                success: successHandler,
                error: errorHandler
            });
        }

Thank you for your help!!

jquery-3.1.1.min.js:2 Uncaught ReferenceError: SP is not defined

解决方案

Ok, I have been testing this code the last two days and i got some improvements.

Now I am available to pass the list name and the subsite name to the url. The issue that remains is the values that the chart needs in order to create the chart (x-value and y-value).

I am trying to use these values like this:


(results).each(function () { chartX.push(this.xValue); chartY.push(this.yValue); });

The problem is that I am getting undefined for both variables (xValue and yValue)

If I do this:


(results).each(function () { console.log(xValue); console.log(yValue); //chartX.push(this.xValue); //chartY.push(this.yValue); });

I get the expected values for the xValues and yValues.

Why I am getting undefined when I use 'this'???

The xValues and yValue are of type string.


这篇关于我可以将vlaues传递给execCrossDomainRequest()吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆