MVC web应用程序作为“app”。 for SharePoint 2013 - jQuery插件无法正常工作 [英] MVC web application as an "app" for SharePoint 2013 - jQuery plugins not working

查看:77
本文介绍了MVC web应用程序作为“app”。 for SharePoint 2013 - jQuery插件无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的MVC Web应用程序包含jQuery插件HighCharts。创建了一个简单的示例,并在本地开发环境中正常运行。所以我们知道这个插件有效。这是一个非常简单的饼图,基于他们的例子。


现在我们使用Visual Studio 2013使用SharePoint App模板创建一个具有相同目的的MVC网站 - 显示图表实用程序,从数据源(例如SQL Server)获取数据,但作为SharePoint应用程序。 然后将此SharePoint应用程序
部署到Office 365 SharePoint站点。


当部署MVC应用程序时,页面会出现但不会出现在图表上的数据。


似乎获取数据的javascript调用未被"解雇"。 当我对应该执行的控制器方法进行调试时,它甚至不会去那里。


这是我第一次在SharePoint应用程序中轻拍,所以我不确定是什么问题。


我最初的想法是Javascript接听电话不正确。 也许是因为我开发出本地环境和网址显示是这样的:HTTP://本地主机:1234 //房产SPHostUrl = HTTPS%3A%2F%2Fmysite%2Esharepoint%2Ecom%2FDev和得到
调用不知道在哪里找到方法?


以下是Javascript调用的示例:

< script type =" text / javascript"> 
//全球图表
var chart;
$(document).ready(function(){

//定义选项
var options = {
chart:{
renderTo:' container',
margin:[50,200,60,170]
},
title:{
text:'浏览器市场份额在特定网站'
},
plotArea:{
shadow:null,
borderWidth:null,
backgroundColor:null
},
tooltip:{
formatter :function(){
return'< b>'+ this.point.name +'< / b>:'+ this.y +'%';
}
} ,
plotOptions:{
pie:{
allowPointSelect:true,
cursor:'pointer',
dataLabels:{
enabled: true,
color:'#000000',
connectorColor:'#000000',
格式:'< b> {point.name}< / b>:{point.percentage :.1f}%'
}
}
},
系列:[]
}
//调用JSON
jQuery。 getJSON(" GetPieChartData",null,function(items){
var series = {
type:'pie',
name:'Browser Share',
data:[ ]
};
jQuery.each(items,function(itemNo,item){
series.data.push({
name:item.Key,
y:parseFloat(item.Value)
})
});
options.series.push(系列);

//创建图表
chart = new Highcharts.Chart(options);
chart.render();
});
});
< / script>

,方法是:

 public JsonResult GetPieChartData()
{
Dictionary< string,decimal> retVal = new Dictionary< string,decimal>();
retVal.Add(" Firefox",45m);
retVal.Add(" IE",26.8m);
retVal.Add(" Chrome",12.8m);
retVal.Add(" Safari",8.5m);
retVal.Add(" Opera",6.2m);
retVal.Add(" Others",0.7m);
返回Json(retVal.ToArray(),JsonRequestBehavior.AllowGet);
}

我认为下面的代码是引起问题的代码?


<预类= "prettyprint" 风格= ""> jQuery.getJSON(QUOT; GetPieChartData" ;,空,功能(项)

I"相当肯定这不是HighCharts jQuery插件的问题,因为我可以在本地开发环境中显示一个图表。当它作为一个应用程序被推送到SharePoint 365环境时,"获取"数据调用不是'执行。 


有任何建议和/或建议吗?


感谢您的时间和帮助。





解决方案

这很奇怪。 我的机器需要做一些更新,所以它有效地重新启动,我不得不从头开始。


今天早上我开始了一个全新的测试SharePoint Apps MVC应用程序,只是为了好玩而且工作正常。


所以...我不完全确定发生了什么。

我在DataTables插件中遇到了类似的问题,这个问题与javascript没有调用控制器的类似情况有关。


但这是另一个线程的讨论。

我会尝试从头开始构建一个新的,看看我能走多远。


感谢那些花时间阅读的人。


我想知道我现在该如何关闭这个帖子?


Our MVC web application contains the jQuery plugin HighCharts. A simple sample was created and works properly on the local dev environment. So we know that this plugin works. It's a very simple pie chart based on their example.

Now we used Visual Studio 2013 using the SharePoint App template to create an MVC website with the same purpose - to display the charting utility getting data from a data source (e.g. SQL Server) but as a SharePoint app.  This SharePoint app would then be deployed to an Office 365 SharePoint site.

When the MVC app is deployed the page comes up but not the data onto the chart.

It seems that the javascript call to get the data isn't "fired".  When I put a debug on the controller method that should be executed it doesn't even go there.

This is my first time dabbing in SharePoint apps so I'm not entirely sure what's wrong.
My initial thought is the Javascript get call is incorrect.  Maybe it's because I'm developing off the local environment and the URL shows something like: http://localhost:1234//Property?SPHostUrl=https%3A%2F%2Fmysite%2Esharepoint%2Ecom%2FDev and the get call doesn't know where to find the method?

Here is a sample of the Javascript call:

<script type="text/javascript">
    //Global Chart
    var chart;
    $(document).ready(function () {

        //define the options
        var options = {
            chart: {
                renderTo: 'container',
                margin: [50, 200, 60, 170]
            },
            title: {
                text: 'Browser market shares at a specific website'
            },
            plotArea: {
                shadow: null,
                borderWidth: null,
                backgroundColor: null
            },
            tooltip: {
                formatter: function () {
                    return '<b>' + this.point.name + '</b>: ' + this.y + ' %';
                }
            },
            plotOptions: {
                pie: {
                    allowPointSelect: true,
                    cursor: 'pointer',
                    dataLabels: {
                        enabled: true,
                        color: '#000000',
                        connectorColor: '#000000',
                        format: '<b>{point.name}</b>: {point.percentage:.1f} %'
                    }
                }
            },
            series: []
        }
        //Calls the JSON
        jQuery.getJSON("GetPieChartData", null, function (items) {
            var series = {
                type: 'pie',
                name: 'Browser Share',
                data: []
            };
            jQuery.each(items, function (itemNo, item) {
                series.data.push({
                    name: item.Key,
                    y: parseFloat(item.Value)
                })
            });
            options.series.push(series);

            //Create the chart
            chart = new Highcharts.Chart(options);
            chart.render();
        });
    });
</script>

and the method is:

  public JsonResult GetPieChartData()
        {
            Dictionary<string, decimal> retVal = new Dictionary<string, decimal>();
            retVal.Add("Firefox", 45m);
            retVal.Add("IE", 26.8m);
            retVal.Add("Chrome", 12.8m);
            retVal.Add("Safari", 8.5m);
            retVal.Add("Opera", 6.2m);
            retVal.Add("Others", 0.7m);
            return Json(retVal.ToArray(), JsonRequestBehavior.AllowGet);
        }

I'm thinking the code below is the one causing the problem?

 jQuery.getJSON("GetPieChartData", null, function (items) 

I'm fairly certain it's not a problem with the HighCharts jQuery plugin because I can get a chart displayed on the local dev environment.  it's when it is pushed to the SharePoint 365 environment as an app that the "get" data call isn't executed. 

Any suggestions and/or recommendations?

Thanks for your time and help.


解决方案

It's weird.  My machine needed to do some updates so it effectively rebooted and I had to start from scratch.
This morning I started a fresh test SharePoint Apps MVC application just for fun and it worked.

So...I'm not entirely sure what was going on.
I had a similar issue with the DataTables plugin that wasn't working with a similar situation that the controller wasn't being called by the javascript.

But that's a discussion for another thread.
I'll try building a new one from scratch and see how far I can get with that.

Thanks to those who took the time to read.

I wonder how I can close this thread now?


这篇关于MVC web应用程序作为“app”。 for SharePoint 2013 - jQuery插件无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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