0

我的离子项目需要一些帮助。所以我想在 ionic 中连接 2 个对象,这样我就可以显示具有来自另一个对象的数据的对象的值。

<ion-list class="list-inset">
  <ion-item class="item-text-wrap" ng-repeat='item in todos| filter:firma'>
  <h2>{{item.company_name}}</h2>
 </ion-item>
 <ion-item class="item-text-wrap" ng-repeat='item in todos2 | filter:{ idcompany:com_id } '>
 <h2>ponedeljek {{item.time_mon_start}}-{{item.time_mon_end}}</h2>
 <h2>torek {{item.time_tue_start}}-{{item.time_tue_end}}</h2>
 <h2>sreda {{item.time_wed_start}}-{{item.time_wed_end}}</h2>
 <h2>četrtek {{item.time_thu_start}}-{{item.time_thu_end}}</h2>
 <h2>petek {{item.time_fri_start}}-{{item.time_fri_end}}</h2>
 <h2>sobota {{item.time_sat_start}}-{{item.time_sat_end}}</h2>
 <h2>nedelja {{item.time_sun_start}}-{{item.time_sun_end}}</h2>
</ion-item>

这是我想为我点击的当前公司显示的内容,但它始终显示的不仅仅是我想要的一个。

.controller('AppCtrl', function($scope, TodoService, cas, $state) {
$scope.todos = [];
$scope.todos2 = [];

function getAllTodos() {
  TodoService.getTodos().then(function (result) {
    $scope.todos = result.data.data;
    $scope.firma = $state.params.aid;

  });
}
getAllTodos();

function getalltimes() {
  cas.getcompany().then(function (result) {
 $scope.todos2 = result.data.data;
});

}

getalltimes();
})

.service('TodoService', function ($http, Backand, $state) {
var baseUrl = '/1/objects/';
var objectName = 'companies/';

function getUrl() {
return Backand.getApiUrl() + baseUrl + objectName;
}
function getUrlForId(id) {
return getUrl() + id;

}
getTodos = function () {
return $http.get(getUrl());
};
return {
getTodos: getTodos
}
})

.service('cas', function ($http, Backand, $state) {
var baseUrl = '/1/objects/';
var time = 'companies_timetable/';

function getUrl2() {
return Backand.getApiUrl() + baseUrl + time;
}
getcompany = function () {
return $http.get(getUrl2());
};
 return {
getcompany: getcompany
}
})

现在这是我的 app.js 文件和我与 backand 服务的连接。这工作正常。

这是来自对象 1 的公司

这是时代的表现

因此,当您单击公司时,它应该显示时间。但在这里它显示了对象中的所有时间。我应该只为我试图在一个数组中提供所有对象的一家公司显示一个(待办事项)。但效果不佳。所以请我需要一些帮助。如果您需要更多代码或其他内容,请直接说出来:)。

4

1 回答 1

0

你的第二个过滤器是错误的。

修复它的最简单方法是调用 $scope 中的函数。

像这样更改您的过滤器:

 <ion-item class="item-text-wrap" ng-repeat='item in todos2 | filter: isCurrentFirma '>

然后在控制器中添加一个函数:

$scope.isCurrentFirma = function(item){
  // here check if item is equal to firma

  // code like this:
  return item.idcompany === $scope.firma.com_id
}
于 2016-05-18T09:34:48.203 回答