实时更新通过match_id检查更新

时间:2015-02-28 17:53:16

标签: jquery json

我正在尝试创建一个更新匹配结果的脚本和live_in,如果它在json文件中更改的话。 json文件是动态的,并且一直在变化。目前它只添加和删除新的匹配,我正在通过比较match_id来做。我正在使用以下代码:

if (lastId) {
  match = match.filter(
    function(match) {
      return match.id > lastId;
    });
 }

除此之外,我创建了一段包含JSON脚本结构的代码片段。我的问题是,如果它在JSON脚本中发生变化,我怎样才能让它更新得分和live_in?

http://plnkr.co/edit/fqcNfLtugI24KqZkXXvi?p=preview

1 个答案:

答案 0 :(得分:0)

鉴于我理解正确:您需要将match.id分发给每个div.result-datespan.result-match-score

例如:

<div class="result-date" id="result-date-id-1">...</div>
<span class="result-match-score" id="result-score1-id-1">...</span>
<span class="result-match-score" id="result-score2-id-1">...</span>

然后,您可以使用match.id

直接查询这些元素
$('div#result-date-id-1').html(...);

示例:http://jsfiddle.net/4x7c692k/1/