根据从解析

时间:2017-08-25 19:16:00

标签: javascript angularjs arrays parse-platform parse-server

我在解析服务器上提供了表和用户表。我做了一个查询,他提供表,它工作得很好(控制台日志和HTML - 我有异步问题和Q.promise帮助)。现在我正在尝试添加users表中的两个元素。我在控制台上得到它,但不在页面上。以下是我在offers.service上的内容:

    this.getAllOffers = function () {

    var Q = $q.defer();
    console.log('getAllOffers called');

    //all offers filter is selected
    this.allOffersFilter = false;

    var offers = Parse.Object.extend("Offer");
    var exchanges = Parse.Object.extend("Exchanges");
    var users = Parse.Object.extend("User");

    var query = new Parse.Query(offers);
    var userQuery = new Parse.Query(users);

    var results = [];

    query.descending("createdAt");
    query.limit(4);

    userQuery.find().then(function(users) {
        for (i = 0; i < users.length; i++) {
            foundUsers = users[i];

            query.find().then( function(offers){
            for(i = 0; i < offers.length; i++){
                found = offers[i];
            var result = {};

            result.date = found.get("createdAt");
            result.price = found.get("price");
            result.status = found.get("accepted");
            result.lastName = foundUsers.get("lastName");
            result.companyName = foundUsers.get("companyName");

            console.log(result.companyName);
            console.log(result.price);
        }
    });
    results.push(result);
  }
  Q.resolve(results);
    });
  return Q.promise;
  };

然后我的HTML:

    <!--List of offers-->
    <div class="col-md-3">
        <h4>List of offers</h4>

        <div ng-if="offersList">
            <div ng-repeat="offer in offersList">
                <div class="offer card">
                    <div>{{offer.username}}</div>
                    <div>{{offer.companyName}}</div>
                    <div>{{offer.date}}</div>
                    <div>{{offer.price}}</div>
                    <div>{{offer.status}}</div>
                </div>
            </div>
        </div>
        <div ng-if="!(offersList)">There are no offers</div>
    </div>

然后是我的组件:

angular.module('offersPage')
.component('offersPage', {
    templateUrl: 'pages/offers-page/offers-page.template.html',
    controller: function(AuthService, PageService, OffersService, 
$scope) {
        // Functions for offers-page

        // Check if user is logged in and verified on page load
        AuthService.userLoggedin(function(loggedIn, verified) {
            if(!verified) {
                PageService.redirect('login');
            }
        });

        this.$onInit =  function() {
            OffersService.getAllOffers().then(function(offersList) {

            $scope.offersList = offersList;
            });
      }
    }
});

感谢提前!

2 个答案:

答案 0 :(得分:0)

当你在angularjs中执行df_sub = samp_data.loc[samp_data['b'].apply(lambda x: not(any([badword in x for badword in unwanted_words]))] 时,它会逐字地取出元素,当它放入它时它就像子范围一样。要解决此问题,您需要确保ng-if放在$parent内的任何子元素上。见下文。确保在重复练习时使用ng-if。另请注意,重复中不需要track by $index任何内容,因为它引用了已定义的$parent

代码:

offer

答案 1 :(得分:0)

您在填充$q之前解析results,因此,您列出的内容为空。

我不了解Parse server,但如果userQuery.find().thenasync,则需要在其中移动Q.resolve(results);,或者可能在{{1}内移动query.find().then }。