0

Knockout.jsを勉強していて、そのチュートリアルデモ「Twitterクライアント」(これはコードへのリンクです)を作成しようとしましたが、まったく機能しません!

私のコードはここにあります:

http://jsfiddle.net/weed_7777/ZZJbv/

私のCoffeeScriptコードは次のとおりです。

root = exports ? this
class root.Twitter
  constructor: ->
    @tweets = []
    $.getJSON('http://search.twitter.com/search.json?callback=?&rpp=100&q=%40weed_7777')
    .done((data) =>
      $.each data.results, (i, item) =>
        @tweets.push item
    )

root = exports ? this
class root.TweetListView
  constructor: ->
    twitter = new Twitter
    @currentTweets = ko.computed =>
      twitter.tweets

ko.applyBindings new TweetListView

$(".loadingIndicator").ajaxStart ->
    $(@).fadeIn()
.ajaxComplete ->
    $(@).fadeOut()

ご親切にありがとうございます。

4

1 に答える 1

1

ツイートはobservableArrayである必要があります。

class root.Twitter
  constructor: ->
    @tweets = ko.observableArray([])
    $.getJSON('http://search.twitter.com/search.json?callback=?&rpp=100&q=%40weed_7777')
     .done((data) =>
      $.each data.results, (i, item) =>
        @tweets.push item
     )

更新されたフィドル作品:

http://jsfiddle.net/hwRBN/

于 2013-03-05T03:45:54.867 に答える