查询中的 jscript 变量

发布于 2024-08-26 14:00:28 字数 4679 浏览 4 评论 0原文

也许是一个非常简单的问题。

我怎样才能在这段代码中放入

<Query>
   <Where>
      <Eq>
         <FieldRef Name="Judge_x0020_1" />
         <Value Type="Text">mr. R. Sanches</Value>
      </Eq>
   </Where>
</Query>

来自 jscript 的变量在 Mr. 所在的代码区域中? R.桑切斯写道。所以我的 jScript 包含一个动态文本变量,我想替换 mr. R.桑切斯与。看看下面哪里写着 THE JAVESCRIPT VAR:

我有的 jScript 代码

<script src="/JavascriptMODS/jPointLoader.js"></script>
<script src="/JavascriptMODS/jPoint.userprofile.js"></script>
<SCRIPT type=text/javascript>
            // Picks the userfield it is going to search with
            var user = jP.getUserProfile();
            var userinfspvalue = user.Department;

            // removes the non breaking space at the end of the departmentfieldcontent
            var removenonbreakingspace = String.fromCharCode(160);
            userinfspvalue = userinfspvalue.replace(removenonbreakingspace,'');
</script>

Userinfspvalue 是我想使用的 var。

在 CAML 查询中

<Query>
   <Where>
      <Eq>
         <FieldRef Name="Judge_x0020_1" />
         <Value Type="Text">Userinfspvalue</Value>
      </Eq>
   </Where>
</Query>

jP.getUserProfile() 是什么?

代码(我没有创建它)。

/*
* name: jPoint.userprofile.js
* purpose: get user profile info from /_layouts/userdisp.aspx
* input: none
* visibility: public
* return: jP.UserProfile (object)
*   jP.UserProfile.Name
*   jP.UserProfile.Account
*   jP.UserProfile.Title
*   jP.UserProfile.EMail
*   jP.UserProfile.Notes
*   jP.UserProfile.AboutMe
*   jP.UserProfile.Picture
*   jP.UserProfile.Department
*   jP.UserProfile.JobTitle
*   jP.UserProfile.SipAddress
*   jP.UserProfile.SIPAddress
*
*   jP.UserProfile.FieldCount   //count of fields
*   jP.UserProfile.Fields       //array of field names
*   jP.UserProfile.Items[0].Name ... SipAddress
*
* use example: 
*   var usrprof = jP.getUserProfile(userID); //userID is optional 
*   var name = usrprof.Name; 
*   var email = usrprof.EMail;
*   var dept = usrprof.Department;
*/
(function(jP) {
    jP.getUserProfile = function (UserID) {
        var ProfileURL = jP.SiteURL+"/_layouts/userdisp.aspx";
        if(typeof UserID !== "undefined")
            ProfileURL = ProfileURL + "?ID=" + UserID;
        $.ajax( {
            type: "GET",    //jQuery ajax GET
            async: false,
            cache: false,
            url: ProfileURL, //userprofile url
            success: function(data){
                var tags = $(data).find("h3 > a");  //look for anchor in h3 tag
                if (tags.length > 0) {
                    var profile = {};
                    var fields = [];
                    var item = {};
                    $.each(tags, function(){
                        var name = this.name;   //name attritbute
                        var td = $(data).find("tr a[name='"+name+"']").parent().parent();  //get label td
                        var labelname = jP.strip(td.text());  //get label text as field name
                        if (labelname == "Picture") {
                            //special handling for Picture field
                            //concat attribute alt and src together
                            var img = td.siblings().find("img");
                            var val = img.attr("alt") + ";#" + img.attr("src");
                        }
                        else {
                            //get text of next td cell
                            var val = $.trim(td.siblings().text());
                        }
                        var intname = name.substr(name.indexOf("_")+1); //internal field name
                        if ($.inArray(intname, fields)==-1) {  //save as internal fieldname
                            fields.push(intname);
                            item[intname] = profile[intname] = val;
                        }
                        if ($.inArray(labelname, fields)==-1) { //save as label fieldname
                            fields.push(labelname);
                            item[labelname] = profile[labelname] = val;
                        }
                    });
                    //Set profile obj
                    profile["Fields"] = fields;
                    profile["FieldCount"] = fields.length;
                    profile["Items"] = [item];
                    //set UserProfile obj
                    jP["UserProfile"] = profile;
                }   
            }
        });
        return (jP["UserProfile"])
    }
})(jPoint);

Maybe a very simple question.

How can I put in this code

<Query>
   <Where>
      <Eq>
         <FieldRef Name="Judge_x0020_1" />
         <Value Type="Text">mr. R. Sanches</Value>
      </Eq>
   </Where>
</Query>

A variable from jscript in the area of the code where mr. R. Sanches is written. So my jScript contains a dynamic text variable I want to replace mr. R. Sanches with. See where it says THE JAVESCRIPT VAR underneath here:

jScript code I have

<script src="/JavascriptMODS/jPointLoader.js"></script>
<script src="/JavascriptMODS/jPoint.userprofile.js"></script>
<SCRIPT type=text/javascript>
            // Picks the userfield it is going to search with
            var user = jP.getUserProfile();
            var userinfspvalue = user.Department;

            // removes the non breaking space at the end of the departmentfieldcontent
            var removenonbreakingspace = String.fromCharCode(160);
            userinfspvalue = userinfspvalue.replace(removenonbreakingspace,'');
</script>

Userinfspvalue is the var I would like to use.

In the CAML query

<Query>
   <Where>
      <Eq>
         <FieldRef Name="Judge_x0020_1" />
         <Value Type="Text">Userinfspvalue</Value>
      </Eq>
   </Where>
</Query>

What is jP.getUserProfile()?

Code (i didnt create it).

/*
* name: jPoint.userprofile.js
* purpose: get user profile info from /_layouts/userdisp.aspx
* input: none
* visibility: public
* return: jP.UserProfile (object)
*   jP.UserProfile.Name
*   jP.UserProfile.Account
*   jP.UserProfile.Title
*   jP.UserProfile.EMail
*   jP.UserProfile.Notes
*   jP.UserProfile.AboutMe
*   jP.UserProfile.Picture
*   jP.UserProfile.Department
*   jP.UserProfile.JobTitle
*   jP.UserProfile.SipAddress
*   jP.UserProfile.SIPAddress
*
*   jP.UserProfile.FieldCount   //count of fields
*   jP.UserProfile.Fields       //array of field names
*   jP.UserProfile.Items[0].Name ... SipAddress
*
* use example: 
*   var usrprof = jP.getUserProfile(userID); //userID is optional 
*   var name = usrprof.Name; 
*   var email = usrprof.EMail;
*   var dept = usrprof.Department;
*/
(function(jP) {
    jP.getUserProfile = function (UserID) {
        var ProfileURL = jP.SiteURL+"/_layouts/userdisp.aspx";
        if(typeof UserID !== "undefined")
            ProfileURL = ProfileURL + "?ID=" + UserID;
        $.ajax( {
            type: "GET",    //jQuery ajax GET
            async: false,
            cache: false,
            url: ProfileURL, //userprofile url
            success: function(data){
                var tags = $(data).find("h3 > a");  //look for anchor in h3 tag
                if (tags.length > 0) {
                    var profile = {};
                    var fields = [];
                    var item = {};
                    $.each(tags, function(){
                        var name = this.name;   //name attritbute
                        var td = $(data).find("tr a[name='"+name+"']").parent().parent();  //get label td
                        var labelname = jP.strip(td.text());  //get label text as field name
                        if (labelname == "Picture") {
                            //special handling for Picture field
                            //concat attribute alt and src together
                            var img = td.siblings().find("img");
                            var val = img.attr("alt") + ";#" + img.attr("src");
                        }
                        else {
                            //get text of next td cell
                            var val = $.trim(td.siblings().text());
                        }
                        var intname = name.substr(name.indexOf("_")+1); //internal field name
                        if ($.inArray(intname, fields)==-1) {  //save as internal fieldname
                            fields.push(intname);
                            item[intname] = profile[intname] = val;
                        }
                        if ($.inArray(labelname, fields)==-1) { //save as label fieldname
                            fields.push(labelname);
                            item[labelname] = profile[labelname] = val;
                        }
                    });
                    //Set profile obj
                    profile["Fields"] = fields;
                    profile["FieldCount"] = fields.length;
                    profile["Items"] = [item];
                    //set UserProfile obj
                    jP["UserProfile"] = profile;
                }   
            }
        });
        return (jP["UserProfile"])
    }
})(jPoint);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情话难免假 2024-09-02 14:00:28

所以有几件事。这是客户端;浏览器执行此 JScript(因此我选择将其称为 JavaScript...最好重新标记它)

您正在使用名为 jPoint 的 JavaScript 库...但您正在尝试操作 CAML询问。

JPoint 通过为您提供诸如 getUserProfile()< 之类的函数来实践所谓的信息隐藏 /code> 但缺点是我不觉得你可以操纵 CAML。事实上,从我在实现中看到的内容以及我在他们的网站上读到的内容来看,我认为它甚至没有 CAML 查询,而只是 屏幕抓取个人资料页面中的 HTML。

总之,我认为您根本不尝试操作 CAML,而是需要找到合适的 jPoint 函数来使用。如果 jPoint 没有,您将不得不放弃它并使用更传统的解决方案。

为什么您使用 jPoint 而不是更传统的东西或服务器端的东西?

So a few things. This is client side; the browser executes this JScript (and as such I'm choosing to refer to it as JavaScript... good call re-tagging it)

You're using a JavaScript library called jPoint... but you're trying to manipulate a CAML query.

JPoint practices what is called Information Hiding by providing you with functions like getUserProfile() but the tradoff is that I don't get the impression you can manipulate the CAML. As a matter of fact, judging by what I see in the implementation and by what I read on their web site, I think it doesn't even CAML query but it just screen scrapes the HTML from profile pages.

So in summary, I don't think you're trying to manipulate the CAML at all but rather need to find the appropriate jPoint function to use. If jPoint doesn't have one, you'll have to ditch it and use a more traditional solution.

Why are you using jPoint instead of something a little more traditional, or server-side?

谁与争疯 2024-09-02 14:00:28

尝试

var type = document.getElementById("testd"); // remember put your things in a div or equal

type.getAttribute('Type').value = "THE JAVASCRIPT VAR";

Try

var type = document.getElementById("testd"); // remember put your things in a div or equal

type.getAttribute('Type').value = "THE JAVASCRIPT VAR";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文