【问题标题】:how to connect 2 objects in ionic via backand如何通过后端连接 ionic 中的 2 个对象
【发布时间】:2016-05-17 10:09:44
【问题描述】:

我的 ionic 项目需要一些帮助。所以我想在 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 服务的连接。这工作正常。

this are the companys from object 1

and this are the times showing

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

【问题讨论】:

    标签: angularjs object ionic-framework backand


    【解决方案1】:

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

    修复它的最简单方法是调用 $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
    }
    

    【讨论】:

    • 不知何故它给了我和我一样的结果。现在我每次都能再次获得,而不仅仅是我需要的。
    • 我进入控制台,它说 com_id 未定义。
    • 好的,功能没问题,但现在我点击公司时它不会显示任何时候
    猜你喜欢
    • 1970-01-01
    • 2021-01-17
    • 1970-01-01
    • 2018-03-08
    • 2012-06-09
    • 1970-01-01
    • 1970-01-01
    • 2017-12-12
    • 1970-01-01
    相关资源
    最近更新 更多