这是我的代码,
(function (module) {
module.controller('TemplatesController', function (Template) {
var model = this;
model.loading = false;
model.templates = [];
model.attributes = [];
model.categories = [];
model.media = [];
init();
function init() {
getTemplates();
}
function getTemplates() {
model.loading = true;
Template.types.query().$promise.then(function (response) {
model.media = response.media;
});
Template.categories.query().$promise.then(function (response) {
model.categories = response.categories;
});
Template.attributes.query().$promise.then(function (response) {
model.attributes = response.attributes;
});
Template.templates.query().$promise.then(function (response) {
model.templates = response.templates;
});
model.loading = false;
}
model.filteredTemplates = function () {
return model.templates.filter(function (template) {
return model.filterBy.indexOf(template.media_category.id) !== -1;
});
};
});
}(angular.module("adbuilder.dealer.templates")));
和html
<div class="filters">
<h4 class="product-filters">Filter Category</h4>
<div data-toggle="buttons">
<label class="btn btn-default btn-block"
ng-repeat="category in templates.categories"
ng-class="{'active': category.isChecked}">
<input type="checkbox" value="{{ category.id}}" ng-model="category.isChecked">
{{ category.name}}
</label>
</div>
<hr>
<h4 class="product-filters">Media</h4>
<div data-toggle="buttons">
<label class="btn btn-default btn-block"
ng-repeat="media in templates.media"
ng-class="{'active': media.isChecked}">
<input type="checkbox" value="{{ media.id}}" ng-model="media.isChecked">
{{ media.name}}
</label>
</div>
<hr>
<h4 class="product-filters">Type</h4>
<div data-toggle="buttons">
<label class="btn btn-default btn-block"
ng-repeat="attribute in templates.attributes"
ng-class="{'active': attribute.isChecked}">
<input type="checkbox" value="{{ attribute.id}}" ng-model="attribute.isChecked">
{{ attribute.name}}
</label>
</div>
</div>
<div ng-repeat="template in filteredTemplates(templates.templates)" class="col-md-4 col-sm-6 m-item">
我在model.attributes
,model.categories
和model.media
中有一系列复选框
templates
。现在我想过滤template.media_category.id
以仅查看选定内容。
template.media_type.id
包含类别ID template.media_type_attribute_options.media_type_attribute_id
包含类型ID ./flyway info
包含属性ID 如何使它有效?目前它什么也没有返回..