【发布时间】:2014-09-30 18:59:53
【问题描述】:
感谢您调查我的问题。我有两个解析类 Game 和 CricketScore。游戏具有指向 CricketScore 类的“first_inning_score”和“second_inning_score”指针。
我只得到指向 CricketScore 的指针,如下所示。 如何从 CricketScore 获取实际数据?(已解决)。现在的问题是如何在车把中显示数据??
我从 parse(updated) 获取这个 JSON 对象
{
"results": [
{
"first_inning_score": {
"overs": "0",
"parent": {
"__type": "Pointer",
"className": "Game",
"objectId": "Yibf5wHLIM"
},
"team_name": "Fr11",
"wickets": "0",
"innings": "1",
"runs": "0",
"createdAt": "2014-09-30T18:27:36.640Z",
"updatedAt": "2014-09-30T18:27:36.640Z",
"objectId": "0NhGUYySg5",
"__type": "Object",
"className": "CricketScore"
},
"second_inning_score": {
"wickets": "0",
"innings": "2",
"runs": "0",
"team_name": "Rb11",
"overs": "0",
"parent": {
"__type": "Pointer",
"className": "Game",
"objectId": "Yibf5wHLIM"
},
"createdAt": "2014-09-30T18:27:36.760Z",
"updatedAt": "2014-09-30T18:27:36.760Z",
"objectId": "4gHyHO84Ep",
"__type": "Object",
"className": "CricketScore"
},
"city": "Poway",
"elected": "bowl",
"groundname": "4s RANCH",
"hometeam": "Rb11",
"maxovers": "20",
"score_moderator": [
{
"__type": "Pointer",
"className": "_User",
"objectId": "00hBJbvgmu"
}
],
"sport": "Cricket",
"status": "inning1",
"team1": "Fr11",
"team2": "Rb11",
"toss": "Rb11",
"createdAt": "2014-09-30T18:27:36.504Z",
"updatedAt": "2014-09-30T18:27:36.898Z",
"objectId": "Yibf5wHLIM"
}
]
}
车把代码
<script type="text/x-handlebars-template" id="single-quote-template">
<!-- Feed Entry -->
<div class="row singleQuote">
<div class="panel" align="center">
<p><h4><strong> {{team1}} vs {{team2}}</strong></h4></p>
<p>Toss won by {{toss}} elected to {{elected}}, {{createdAt}}, {{groundname}}</p>
<p>{{first_inning_score.wickets}}</p> // ** <<---this is not working****
</div>
</div>
<hr />
</script>
Javascript 代码。我还不知道如何获得板球得分。我无法在下面遵循 Dehli 的回答。
query.find({
success: function(results) {
// The query was successful, and has passed
// back an array of PFObjects for you to use
// Since we're appending, clear the list out
// every time we're about to add results
$("#quoteList").html("");
// Compile the Handlebars template we're going
// to stick the results into. Pass Handlebars the
// ID of the script tags in index.html that contain
// the template.
var template = Handlebars.compile($("#single-quote-template").html());
// Iterate over all the results
$(results).each(function(i,e) {
// Serialize the PFObject and store it in q
var q = e.toJSON();
// Select the DOM element we're appending to,
// Then append the template, passing in q to
// provide the values of the template variables
$("#quoteList").append(template(q));
});
},
error: function(error) {
if (error.message == "unauthorized") {
// Temporary message if you haven't added your own credentials for Parse.com yet. Remove once set up.
console.warn("Please fill in your own Parse.com App ID and Javascript Key on line 107 of index.html");
}
// Handle the error here
}
})
【问题讨论】:
-
您的查询是什么样的?尝试添加
query.include("first_inning_score");和query.include("second_inning_score"); -
非常感谢!!!!这已经奏效了。你能告诉我如何将第一局得分的数据放到手柄上吗?请参阅上面的更新代码
标签: javascript json serialization parse-platform