2013-07-15 39 views
0

試圖創建一個自定義鼠標懸停約束力不工作,但我有麻煩。我不斷收到錯誤自定義鼠標懸停在結合knockout.js

Uncaught ReferenceError: Unable to parse bindings. 
Bindings value: FadeIn: $data, event: {mouseover: Flash} 
Message: Flash is not defined 

任何想法?繼承人我的提琴手http://jsfiddle.net/ricobano/YuyV6/5/

<ul data-bind="foreach: News"> 
     <li data-bind="FadeIn: $data, event: {mouseover: Flash}"> 
      <div class="InfoWrapper"> 
       <span data-bind="text: formatTime()"></span> 
      </div> 
      <div class="NewsWrapper"> 
       <h3 data-bind="text: StrapLine"></h3> 
       <div class="NewsBody" data-bind="html: Body"></div> 
      </div> 
      <br style="clear:both;"/> 
     </li> 
    </ul> 

JS

ko.bindingHandlers.FadeIn = { 
    init: function(element, valueAccessor){ 
     $(element).hide(); 
    }, 
    update: function(element, valueAccessor){ 
     $(element).fadeIn(1000); 
    } 
}; 

ko.bindingHandlers.Flash = { 
    update: function(element, valueAccessor){ 
     console.log($(element).html()); 
     $(element).animate({ 
      "background-Color": "Red" 
      }, 100); 
    } 
}; 

function News(data){ 
    this.Id = data.Id; 
    this.Time = data.Time; 
    this.StrapLine = data.StrapLine; 
    this.Icon = data.Icon; 
    this.Body = data.Body; 

    this.formatTime = function(){ 
     return this.Time + ":"; 
    }; 
} 

function NewsVM(){ 
    var self = this; 
    self.Increment = 0; 

    self.TempArray = [ 
     new News({id:"1", Time:"9.40", StrapLine:"FOOTBALL", Icon:"Icon", Body:"<p>Manchester United manager David Moyes has been keeping busy since arriving in Australia, spending his time making a £25m bid for Cesc Fabregas and preparing his team for Saturday's friendly against the A-League All-Stars.</p><p>It has not been all work for Moyes, however, as the Scot enjoyed taking several pictures of the iconic scenery on show in Sydney Harbour at the weekend.</p>"}), 
     new News({id:"2", Time:"9.50", StrapLine:"WOMEN'S FOOTBALL", Icon:"Icon", Body:"<p>BBC Sport's Alistair Magowan reports from Linkoping: \"In her BBC Sport column, England skipper Casey Stoney says no-one's place is safe for the match against Russia tonight following the opening Euro 2013 defeat by Spain.</p><p>From what we are hearing, though, boss Hope Powell could be prepared to give the team a second chance. But there are some talented youngsters such as Arsenal midfielder Jordan Nobbs and Everton striker Toni Duggan waiting in the wings.\"England v Russia is live on BBC2 tonight with the programme beginning at 16:30 BST with kick-off at 17:00 BST. There is also live text commentary on the BBC Sport website.</p>"}), 
     new News({id:"3", Time:"9.52", StrapLine:"ATHLETICS", Icon:"Icon", Body:"<p>Michelle Verroken, former director of ethics and anti-doping for UK Sport, tells BBC Radio 5 live there needs to be more action taken to help athletes after the failed drug tests of sprinters Asafa Powell and Tyson Gay.</p><p>\"It's devastating for the sport and a huge surprise,\" said Verroken.</p>"}), 
     new News({id:"4", Time:"9.58", StrapLine:"FORMULA 1", Icon:"Icon", Body:"Susie Wolff will have her first full Formula 1 test at the wheel of a Williams in this week's 'young-driver' test at Silverstone.Wolff, 30, is currently the development driver for Williams. She raced in the DTM German touring car championship for seven years before quitting the series to concentrate on her work with the British outfit.\"There is very limited testing, so you only get one chance. You have to grab it with both hands\", she tells BBC Radio 5 live"}), 
     new News({id:"5", Time:"10.02", StrapLine:"FOOTBALL - CESC FABREGAS", Icon:"Icon", Body:"One Manchester United fan has been quick to celebrate the possible arrival of Barcelona's Cesc Fabregas.The midfielder's Wikipedia page has been updated to incorrectly state.\"On the 17th of July Cesc moved to sunny Manchester, and was quoted as saying \"it is good to be playing for a team in England where I can actually win things\".But what is your reaction to the news? How good a signing would he be for Manchester United? Arsenal fans, how would you feel if your former captain joined David Moyes's side?Let us know your thoughts on Twitter, via #bbcsportsday"})]; 

    this.News = ko.observableArray(); 

    self.AddNews = function(){ 
     if(self.TempArray.length -1 == self.Increment){ 
      self.Increment = 0; 
      self.News.removeAll(); 
      return; 
     } 

     self.News.unshift(self.TempArray[self.Increment]); 
     self.Increment++; 
    }; 

    setInterval(function(){ 
     console.log("called"); 
     self.AddNews(); 
     },5000 
    ); 
} 


ko.applyBindings(new NewsVM()); 
+0

這在這篇文章中,http://stackoverflow.com/questions/15840975/unable-to-parse-bindings-knockout-error的回答。總之,如果你改變成'$ root.Flash'你的小提琴將開始工作。 – veritasetratio

回答