我有一个问题/问题,如何使用ng-repeat从数据库中查看对象,但是在此对象中的项目之后进行过滤,例如我在标题四电脑的products
中有十个对象,四个电视两个移动电话。我的问题是如何使用ng-repeat查看此产品但在标题中过滤?我想分别查看不同标题的产品
Mongo Schema
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var productSchema = new Schema({
imagePath: {
type: String,
require: true
},
title: {
type: String,
require: true,
},
subTitle: {
type: String,
require: true
},
newPrice: {
type: Number,
require : true,
}
});
module.exports = mongoose.model('Product', productSchema);
控制器功能
function getProducts() {
User.getProducts().then(function(data){
app.products = data.data.products;
console.log(data.data.products);
app.loading = false;
})
}
getProducts()
html视图
<div ng-repeat="product in main.products" class="col-xs-12 col-sm-10" >
<div class="all_course_view slideanim">
<div class="thumbnail image_course">
<img src="../../uploads/{{ product.imagePath }}" alt="#"/>
</div>
<div class="caption">
<h3>{{ product.title }}</h3>
<h4>{{ product.subTitle }}</h4>
</div>
</div>
</div>
答案 0 :(得分:1)
您可以按照标题过滤结果。 Curtosy of AngularJS Filter Documentation
HTML:
<p>Filter by Title: <input ng-model="search.title"></p>
<div ng-repeat="product in main.products | filter:search" class="col-xs-12 col-sm-10" >
...