bxSlider 2天前停止工作,没有代码更改 [英] bxSlider Stopped Working 2 Days ago with no code changes
问题描述
我一直把我的头发拉出来。我们在SharePoint 2013主页中实现了bxslider。这项工作是由我现在离开的同事完成的,所以不是我的工作,但....它是完成和工作。
现在,虽然我调用onSliderLoad回调函数调用slider.goToNextSlide()时收到运行时错误;
从调试输出窗口提取VS:
0x800a138f - JavaScript运行时错误:无法获取未定义或空引用属性goToNextSlide
$ b
我几乎排除了代码更改,因为我已经还原了源代码几个月,还将一个非常旧的快照还原到虚拟SharePoint服务器。这些都仍然经历同样的新问题。我也试过这个技巧在我们的临时服务器,没有任何新发布的代码了一段时间。此主机现在遇到相同的问题。只有我能想到的是有一个外部的变化,这是引起这个问题,但我不知道。
我得到不同的错误Firebug和IE10 SharePoint您必须在IE中测试和调试; - ))
从FeedsRotator.ascx提取(Home.aspx上的Webpart)
var slider = $('#slider2')。bxSlider({
auto:true,
控制:false,
pager:false,
pause:
slideWidth:(sir?sirina:300),
slideHeight:450,
randomStart:true,
autoHover:true,
onSliderLoad:function(currentIndex){
slider.goToNextSlide(); //这是行1024
},
从BxSlider.css提取
#slider1 {
margin:0;
padding:0;
}
.bx-wrapper {
position:relative;
margin:10px;
padding:0;
* zoom:1;
}
.bx-wrapper img {
max-width:100%;
display:block;
}
忘记说我们正在使用jquery 1.9.1。
所以,我正在用客户端代码完成错误的树。这是因为填充新闻滑块的Annoucements列表项目已在5天前过期。
因此是在webpart上查询未返回任何数据的列表的服务器端代码:
string Qry =< Where>< Geq>< FieldRef Name ='Expires'/>< Value IncludeTimeValue ='FALSE'Type ='DateTime' > {0}< / Value>< / Geq>< / Where>;
protected void Page_Load(object sender,EventArgs e)
{
if(!((Page)System.Web.HttpContext.Current.CurrentHandler).IsPostBack )
{
DisplayAnnouncements();
}
}
private void DisplayAnnouncements()
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using使用(SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))
{
SPList list = web.Lists [Announcements];
SPQuery query = new SPQuery();
query.RowLimit = 10;
query.Query = string.Format(Qry,DateTime.Now.ToString (yyyy-MM-dd));
rep1.DataSource = list.GetItems(query).GetDataTable();
rep1.DataBind();
}
}
}
);
}
现在我必须决定如何处理
选项1(查找最近过期的公告):
private void DisplayAnnouncements b $ b {
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using(SPSite site = new SPSite(SPContext.Current.Site.ID))
{
使用(SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))
{
SPList list = web.Lists [Announcements];
SPQuery query = new SPQuery ;
query.RowLimit = 10;
DateTime queryDate = DateTime.Now;
query.Query = string.Format(Qry,queryDate.ToString(yyyy-MM-dd );
while(list.GetItems(query).Count == 0&& amp; queryDate> new DateTime(2000,1,1))//停止一个不定式循环是空的
{
TimeSpan oneDay = new TimeSpan(1,0,0,0);
queryDate = queryDate - oneDay;
query = new SPQuery(){Query = string.Format(Qry,queryDate.ToString(yyyy-MM-dd))};
}
rep1.DataSource = list.GetItems(query).GetDataTable();
rep1.DataBind();
}
}
}
);
}
选项2(不显示新闻)
private void DisplayAnnouncements()
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using(SPSite site =新的SPSite(SPContext.Current.Sid.ID))
{
使用(SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))
{
bool oldAllowUnsafeUpdates = web.AllowUnsafeUpdates;
web.AllowUnsafeUpdates = true;
web.Update();
SPList list = web.Lists [Announcements];
SPQuery query = new SPQuery();
query.RowLimit = 10;
DateTime queryDate = DateTime.Now;
query.Query = string.Format(Qry,queryDate.ToString yyyy-MM-dd));
if(list.GetItems(query).Count == 0)
{
SPListItem noNewsListItem = list.AddItem();
noNewsListItem [Title] =NoCurrentNews;
noNewsListItem [MainDisplayImage] =< img src = \/sites/OMGIntranet/SiteAssets/NO-CURRENT-NEWS-STORIES.jpg\>< / img>;
noNewsListItem [Expires] = DateTime.MaxValue;
noNewsListItem.Update();
}
rep1.DataSource = list.GetItems(query).GetDataTable();
rep1.DataBind();
web.AllowUnsafeUpdates = oldAllowUnsafeUpdates;
}
}
}
);
}
I've been pulling my hair out with this. We have an implementation of bxslider in a SharePoint 2013 home page. This work was completed by my now departed collegue, so not my work, but .... it was finished and working.
Now though I get a runtime error when calling onSliderLoad callback function which calls slider.goToNextSlide();
Extract from Debug Output window VS: 0x800a138f - JavaScript runtime error: Unable to get property 'goToNextSlide' of undefined or null reference
I've pretty much ruled out a code change because I've reverted the source code back months and also restored a very old snapshot into the virtual SharePoint server. These all still experience the same new issue. I also tried this trick on our staging server which hasn't had any newly released code for a while. This host is now experiencing the same issue. Only thing I can think is that there is a external change which is causing this issue, but what I have no idea.
I get different errors from Firebug and IE10 (It's SharePoint you have to test and debug in IE as well ;-))
Extract from FeedsRotator.ascx (Webpart on Home.aspx)
var slider= $('#slider2').bxSlider({
auto: true,
controls: false,
pager:false,
pause: 10000,
slideWidth: (sir ? sirina:300),
slideHeight: 450,
randomStart: true,
autoHover: true,
onSliderLoad: function (currentIndex) {
slider.goToNextSlide(); //This is line 1024
},
Extract from BxSlider.css
#slider1 {
margin:0;
padding:0;
}
.bx-wrapper {
position: relative;
margin: 10px;
padding: 0;
*zoom: 1;
}
.bx-wrapper img {
max-width: 100%;
display: block;
}
Forgot to say we're using jquery 1.9.1.
So, I was completely barking up the wrong tree with the clientside code. It was infact that the Annoucements List items which populate the news slider had expired 5 days ago.
It was therefore the server side code on the webpart which queries the list which wasn't returning any data:
string Qry = " <Where><Geq><FieldRef Name='Expires' /><Value IncludeTimeValue='FALSE' Type='DateTime'>{0}</Value></Geq></Where>";
protected void Page_Load(object sender, EventArgs e)
{
if (!((Page)System.Web.HttpContext.Current.CurrentHandler).IsPostBack)
{
DisplayAnnouncements();
}
}
private void DisplayAnnouncements()
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))
{
SPList list = web.Lists["Announcements"];
SPQuery query = new SPQuery();
query.RowLimit = 10;
query.Query = string.Format(Qry, DateTime.Now.ToString("yyyy-MM-dd"));
rep1.DataSource = list.GetItems(query).GetDataTable();
rep1.DataBind();
}
}
}
);
}
So now I have to decide how to handle this
Option 1 (find the most recently expired announcements):
private void DisplayAnnouncements()
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))
{
SPList list = web.Lists["Announcements"];
SPQuery query = new SPQuery();
query.RowLimit = 10;
DateTime queryDate = DateTime.Now;
query.Query = string.Format(Qry, queryDate.ToString("yyyy-MM-dd"));
while (list.GetItems(query).Count == 0 && queryDate > new DateTime(2000, 1, 1)) //Stop an infinitive loop where list is empty
{
TimeSpan oneDay = new TimeSpan(1, 0, 0, 0);
queryDate = queryDate - oneDay;
query = new SPQuery() { Query = string.Format(Qry, queryDate.ToString("yyyy-MM-dd")) };
}
rep1.DataSource = list.GetItems(query).GetDataTable();
rep1.DataBind();
}
}
}
);
}
Option 2 (Display No News)
private void DisplayAnnouncements()
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))
{
bool oldAllowUnsafeUpdates = web.AllowUnsafeUpdates;
web.AllowUnsafeUpdates = true;
web.Update();
SPList list = web.Lists["Announcements"];
SPQuery query = new SPQuery();
query.RowLimit = 10;
DateTime queryDate = DateTime.Now;
query.Query = string.Format(Qry, queryDate.ToString("yyyy-MM-dd"));
if (list.GetItems(query).Count == 0)
{
SPListItem noNewsListItem = list.AddItem();
noNewsListItem["Title"] = "NoCurrentNews";
noNewsListItem["MainDisplayImage"] = "<img src=\"/sites/OMGIntranet/SiteAssets/NO-CURRENT-NEWS-STORIES.jpg\"></img>";
noNewsListItem["Expires"] = DateTime.MaxValue;
noNewsListItem.Update();
}
rep1.DataSource = list.GetItems(query).GetDataTable();
rep1.DataBind();
web.AllowUnsafeUpdates = oldAllowUnsafeUpdates;
}
}
}
);
}
这篇关于bxSlider 2天前停止工作,没有代码更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!