NG-重复与合并数组对象工作 [英] ng-repeat not working with merged array objects

查看:206
本文介绍了NG-重复与合并数组对象工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的基础上, YDN-DB包

var db = new ydn.db.Storage('Trans');

    var iter_supplier = new ydn.db.IndexValueIterator('stops', 'stop_id');
    var iter_part = new ydn.db.IndexValueIterator('times', 'stop_id');
    var req = db.scan(function(keys, values) {
        var SID = keys[0];
        var PID = keys[1];
        // console.log(SID, PID);
        if (!SID || !PID) {
            return []; // done
        }
        var cmp = ydn.db.cmp(SID, PID); // compare keys
        if (cmp == 0) {
            // console.log(values[0], values[1]);
            var merged = angular.extend(values[0], values[1]);
            console.log(merged);

            $scope.results = merged;
            // $scope.$apply(function() {
            //     $scope.results = merged;
            // });

            return [true, true]; // advance both
        } else if (cmp == 1) {
            return [undefined, SID]; // jump PID cursor to match SID
        } else {
            return [PID, undefined]; // jump SID cursor to match PID
        }
    }, [iter_supplier, iter_part]);

控制台浏览器的结果看起来是这样的:

和我通过与NG-重复的尝试循环:

And I'm trying to loop through with ng-repeat as:

    <div class="medium-6 columns" ng-repeat="result in results">
        <div class="card hoverable">
            <div class="content">
                <span class="title">{{ result }}</span><small class="float-right">{{result.stop_id}}</small>
                <div class="divider"></div>
                <p>Times: {{ result.arrival_time }}</p>
            </div>
        </div>
    </div>  

我什么也没得到与NG重复的HTML。它似乎没有通过循环。我在做什么错了?

I get nothing in the html with ng-repeat. It doesn't seem to loop through. What am I doing wrong?

推荐答案

合并看起来是一个单一的对象,目前在每次迭代打印出来。你的意思是被设定结果到单个对象或会想寻找类似 $ scope.results.push(合并),而不是建立一个结果列表?

merged appears to be a single object, currently printed out on each iteration. Do you mean to be setting results to that single object or would you be looking for something like $scope.results.push(merged) instead to build up a list of results?

它看起来像你想有一个列表,而不是一个单一的对象,但如果你不这样做,和结果将是一个单一的对象/字典相反,您将通过使用 NG-重复=(键,值)的结果键和值循环

It does look like you want a list instead of a single object, but if you don't, and results is going to be a single object/dictionary instead, you would loop through the keys and values using ng-repeat="(key, value) in results".

这篇关于NG-重复与合并数组对象工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆