NG-重复与合并数组对象工作 [英] ng-repeat not working with merged array objects
问题描述
我有这样的基础上, 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屋!