简体   繁体   中英

Need to render specific index/location of returned results from MongoDB query

Using AngularJS and MognoDB, is it possible to query the database, return the results, and then render the results in an angular view, BUT AT A SPECIFIC INDEX/LOCATION OF THE RETURNED DATA?

NOTE: OBJECTS ARE RETURNED IN ARRAY...

For example:

User clicks an <a> tag with ui-sref leading into View2 from View1. URL triggers query to MongoDB, returning 500 results. In View2, I need to render the results in a pagination format (already completed), but have the pagination START at the specific result that the <a> tag was on.

PROBLEM: The results are returned and the View2 is rendered, but the results START at the beginning of the returned list, rather then at the specific result that was clicked from View1.

<div class="col m3" dir-paginate="material in graniteStuff | itemsPerPage: 20">
          <a ui-sref="material({id: material.material_category_id})"><div class="card">
            <div class="card-image small">
                <img ng-src="http://...">
            </div>
            <div class="card-content" id="color">
              <p>{{ material.material_name }}</p>
              <p>{{ material.material_country_of_origin }}</p> 
            </div>
            </div>
          </a>
        </div>

I'm passing the id as a parameter through the ui-sref to the query, but I need to ALSO pass the name of the material as a parameter, or somehow BEGIN the returned results at that specific location.

Your search query needs to take the pageindex and pagesize and return a subset of the total results, along with the number of pages given the pagesize.

Then you can render the paging elements, set the 'active' pager button and only render the results for that page.

.skip(pageindex * pagesize).limit(pagesize) // pageindex is 0 based

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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