简体   繁体   English

Backbone.js:我正在使用Web服务调用来使用Backbone.js获取集合对象,如何在html中显示集合响应对象数据?

[英]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?

I am using web service call in a Backbone.js script to get the collection objects response in console using following code: 我在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");}
});
});

});

I got the following response in my console : 在控制台中收到以下响应

 "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",

    },

Now I want to display the deckId, createdDateTime, deckName in html format in the below code: 现在,我想在以下代码中以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>

How do I display the response I got in console on html page ? 如何显示在html页面上的控制台中得到的响应? Please help . 请帮忙

As for what i am understanding you are new to Backbone.js so i would request you go through some tutorials rather than just getting the code made up by some other person and just add that piece of code to your existing one. 至于我所了解的,您是Backbone.js的新手,所以我将要求您阅读一些教程,而不是仅由其他人编写代码,而是将这段代码添加到现有代码中。

So here are the links: Backbone.js tutorials and learning resources 因此,这里是链接: Backbone.js教程和学习资源

If you have any doubts i will be more than glad to help you out in that case. 如果您有任何疑问,在这种情况下,我将非常高兴为您提供帮助。 Hope you will follow my heed and learn instead of copy. 希望您能遵循我的注意,学习而不是复制。

As you are using Backbone , you can just use underscore template engine because it's a dependency of Backbone. 使用Backbone时,您只能使用下划线模板引擎,因为它是Backbone的依赖项。 You can read more about it here -> How to use underscore.js as a template engine? 您可以在这里了解更多信息-> 如何使用underscore.js作为模板引擎?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM