Meteor 從一個列表頁進入詳情頁如何快速顯示詳情,meteor列表詳情

來源:互聯網
上載者:User

Meteor 從一個列表頁進入詳情頁如何快速顯示詳情,meteor列表詳情

       不管是做android開發,還是做網頁web開發,都 會有列表,都需要點擊列表進入清單項目的詳情頁面,查看詳細資料,能常情況下,我們都是將這一清單項目的id傳到詳情頁,由詳情頁再到資料庫查詢詳細資料。

     在用Meteor開發網站中,除了用傳id的方法,外還提供了一種簡單的方法,極大的方便了我們的開發,節省時間。


原文:http://blog.csdn.net/casun_li/article/details/46371811


1. 建立詳情頁的route  並傳資料:


  (1)如可按傳id的方法,則這樣:


this.route('detail', {    path: '/detail/:app_id',    data: function() {        return {app_id: this.params.app_id};//將id傳入到詳情頁面    }});(2)使用新方法(我將之叫做:傳對象的方法)我寫在後面的步驟都是按之來繼續的:
this.route('detail', {    path: '/detail/:_id',    onBeforeAction: function() {        Meteor.subscribe("detailInId",this.params._id);//定閱 :定閱單條資訊        this.next();    },    data: function() {        return appdocs.findOne({_id:this.params._id});//為詳情頁提供對象         //此處一定要用 findOne() 而不能用find()(它得到的是一個cursor對象) 如何一定要用則就是find({_id:_id}).fetch()[0] ,因為頁面用的是這個詳情的對象,而不是cursor對象    }});

2.伺服器的推送

Meteor.publish("detailInId", function (_id) {    return appdocs.find({_id:_id});//此處要用find()頁不能用findOne() 因為publish提應該提供cursor 或 數組。});



3.詳情頁,點頁列表頁的連結<ahref="detail/{{_id}}">點擊查看</a>  進入詳情後,可以直接使用詳情對象來顯示內容了.例如

appdocs表中有name  和 url 這兩個欄位 ,則使用
{{url}} 
{{name}}
就能顯示內容,原因是在第一步的data中:return appdocs.findOne({_id:this.params._id}),meteor將它(為了理解,假設這個對象取名為:app)傳入了template detail中,
因此我們在調用{{name}}時就是調用了{{app.name}}

html:

<template name="detail">

<div class="form-group">    <label class="col-sm-2 control-label">:</label>    <div class="col-sm-10">        <p class="form-control-static">{{url}}</p>    </div></div><div class="form-group">    <label class="col-sm-2 control-label">應用程式名稱:</label>    <div class="col-sm-10">        <p class="form-control-static">{{name}}</p>    </div></div>

</template>



4. 簡單給出列表頁 html

   <template name="applist">
<table class="table table-striped  table-hover">    <thead>      <tr>         <td >操作        </td>      </tr>    </thead>    <tbody>    {{#each apps}}        {{> appitem}}    {{/each}}    </tbody></table>

    </template>
<template name="appitem">    <tr >        <td ><a href="detail/{{_id}}">點擊查看</a></td>     </tr></template>


原文:http://blog.csdn.net/casun_li/article/details/46371811
參考:https://github.com/iron-meteor/iron-router/blob/master/Guide.md

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.