我在Backbone.js脚本中使用Web服务调用,使用以下代码在控制台中获取集合对象响应:
<script>
$(document).ready(function(){
var pgServerName =$("#serverName").text();
var pgPort =$("#serverPort").text();
var pgProjectName =$("#projectName").text();
var userLogged =$("#loggedInUser").text();
$("button").on('click', function(){
Server=Backbone.Model.extend({});
ServerList= Backbone.Collection.extend(
{
model:Server,
url:"/MicroStrategy/servlet/taskProc?taskId=getAllUserDecks&taskEnv=xhr&taskContentType=json&iServer="+pgServerName+"&port="+pgPort+"&userId="+userLogged+"&authMode=64&projName="+pgProjectName,
initialize:function(){
alert('In collection init');
}
}
);
list=new ServerList;
list.fetch({
success:function(collection, response)
{
alert(response);
console.log(response);
},
error:function(){alert("error");}
});
});
});
我在我的控制台中获得了以下响应:
"deckIds": Array[3] [
0 Object {
"port": "30170",
"deckName": "Interactive Sandbox",
"projName": "CFO Sandbox",
"createdDateTime": "3/5/2015 11:39:36 AM",
"deckId": "12",
},
Object 1 {
"port": "30170",
"deckName": "Standard Management Reporting",
"projName": "Standard Management Reporting",
"createdDateTime": "2/18/2015 8:15:14 AM",
"deckId": "1",
},
Object 2{
"port": "30170",
"deckName": "Month End Tracking Reports",
"projName": "Standard Management Reporting",
"createdDateTime": "2/12/2015 7:24:01 AM",
"deckId": "3",
},
现在我想在下面的代码中以html格式显示 deckId,createdDateTime,deckName :
<table id="example">
<thead>
<tr>
<th>deckId</th>
<th>deckName</th>
<th>createdDateTime</th>
</tr>
</thead>
<tbody>
<tr>
<td>actual data from deckId</td>
<td>actual data from deckName</td>
<td>actual data from createdDateTime </td>
</tr>
</tbody>
</table>
如何在html页面上显示我在控制台中获得的响应?请帮助。
答案 0 :(得分:0)
至于我所理解的你是Backbone.js的新手,所以我会要求你通过一些教程,而不是仅仅获取由其他人编写的代码,只需将那段代码添加到现有的代码中。
以下是链接:Backbone.js tutorials and learning resources
如果您有任何疑问,我会非常乐意在这种情况下帮助您。 希望你能听从我的注意并学习而不是复制。
答案 1 :(得分:0)
当您使用Backbone时,您可以使用下划线模板引擎,因为 它是Backbone的依赖。你可以在这里阅读更多相关信息 - &gt; How to use underscore.js as a template engine?