JavaScript将值发送给另一个函数

时间:2016-06-02 13:12:35

标签: javascript

我正在尝试发送" MyProject"以下功能如下。 (我只想将SPservice的值发送到另一个脚本)。我该如何结合这个呢?



<script language="javascript" type="text/javascript">

$(document).ready(function() {
  $().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "MyCustomList",
    CAMLViewFields: "<ViewFields></ViewFields>",
    completefunc: function (xData, Status) {
      $(xData.responseXML).SPFilterNode("z:row").each(function() {
        var MyProject = $(this).attr("ows_Project");
		
		});
    }
  });
});
</script>

<script language="javascript" type="text/javascript">
$(document).ready(function () {		
            var appointments = new Array();
            var appointment1 = {
                
                description: "George brings projector for presentations.",
                location: "",
                subject: "Quarterly Project Review Meeting",
                Project: <I want MyProject to here>,
				
                
            }
	});
</script>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:1)

<script language="javascript" type="text/javascript">
    $(document).ready(function() {
     $().SPServices({
        operation: "GetListItems",
        async: false,
        listName: "MyCustomList",
        CAMLViewFields: "<ViewFields></ViewFields>",
        completefunc: function (xData, Status) {
           $(xData.responseXML).SPFilterNode("z:row").each(function() {
                var MyProject = $(this).attr("ows_Project");
                myFunction(MyProject)
           });
        }
    });
   });

function myFunction(myProject){
        var appointments = new Array();
        var appointment1 = {

            description: "George brings projector for presentations.",
            location: "",
            subject: "Quarterly Project Review Meeting",
            Project: myProject,


        }
}
</script>

答案 1 :(得分:0)

您可以命名第一个功能,最后命名

return MyProject;

然后在第二个函数上,你只需调用上一个函数

Project: NameOfFirstFunction(),