我需要基於json響應構建一個表,調用API時調用API, 調用API並讓JSON工作正常,但我沒有發現任何有關構建表的文檔並從x.js傳遞給x.html。我成功地從json傳遞了1個參數/值。將json數據提交到html表中
的json看起來像這樣:(這是詹金斯API結果)
{
"builds":
[
{
"duration": 24503,
"id": "2013-12-11_19-48-55",
"number": 33,
"result": "FAILURE",
"timestamp": 1386791335164
},
{
"duration": 24553,
"id": "2013-12-11_19-00-27",
"number": 32,
"result": "FAILURE",
"timestamp": 1386788427803
},
{
"duration": 24237,
"id": "2013-12-11_18-59-51",
"number": 31,
"result": "FAILURE",
"timestamp": 1386788391179
},
JS代碼
Meteor.call('jenkinsServiceBuild', function(err, respJson) {
if(err) {
window.alert("Error: " + err.reason);
console.log("error occured on receiving data on server. ", err);
} else {
//window.alert("Success: ");
console.log("respJson: ", respJson.builds[1].id);
//window.alert(respJson.length + ' tweets received.');
var buildsList = respJson.builds[1].id;
Session.set("recentBuilds", respJson.builds[1].id);
}
$('#buildButton').removeAttr('disabled').val('build');
})
},
});
Template.dashboard.helpers({
recentBuilds : function() {
return Session.get("recentBuilds");
//recentBuilds: buildsList
} });
HTML代碼
<template name="dashboard">
<div class="control-group">
<div class="controls">
<input type="button" value="build" class="btn btn-info" id="buildButton"/>
</div>
<br><br>
___{{recentBuilds}}___
</template>
感謝 羅南
我會建議使用從YUI一個確定年代類或引導它會讓你的工作很很容易 – AMY