[英]Backbone.js - How to get an array of object literals out of a collection?
[英]Backbone.js: I am using web service call to get collection object using Backbone.js, How to display the collection response object data in html?
我在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頁面上的控制台中得到的響應? 請幫忙 。
至於我所了解的,您是Backbone.js的新手,所以我將要求您閱讀一些教程,而不是僅由其他人編寫代碼,而是將這段代碼添加到現有代碼中。
因此,這里是鏈接: Backbone.js教程和學習資源
如果您有任何疑問,在這種情況下,我將非常高興為您提供幫助。 希望您能遵循我的注意,學習而不是復制。
使用Backbone時,您只能使用下划線模板引擎,因為它是Backbone的依賴項。 您可以在這里了解更多信息-> 如何使用underscore.js作為模板引擎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.