从指标阵列获取一个火力点列表
我已下令故事的指标:从指标阵列获取一个火力点列表
{
index: ["storyA", "storyB", "storyC"]
}
我想引用的故事,并把它传递到angularFireCollection
{
index: ["storyA", "storyB", "storyC"],
stories: {
"storyA" : {},
"storyB" : {},
"storyC" : {},
"storyD" : {},
"storyE" : {}
},
}
这是例子从篝火。这将得到所有的故事,而不仅仅是索引中的那些故事。我如何得到索引中的那些?
app.controller('stories', ['$scope', '$timeout', 'angularFireCollection',
function($scope, $timeout, angularFireCollection) {
var url = 'https://example.firebaseio.com/stories';
$scope.stories = angularFireCollection(url);
}
]);
Harry,请查看FirebaseIndex了解如何使用索引的示例。几乎所有使用Firebase进行的工作都将涉及索引或记录规范化(通过id匹配两组记录),因此这是一个值得研究的重要主题。
索引不会与AngularFire开箱即用。然而,有一点思想和pull请求可以提交允许它直接与FirebaseIndex工作(只是通过在FirebaseIndex而不是URL,并在AngularFire构造,设置this._fref
到FirebaseIndex而不是new Firebase(url)
。
例如:
function AngularFire($q, $parse, url) {
this._q = $q;
this._parse = $parse;
this._initial = true;
this._remoteValue = false;
this._fRef = typeof(url) === 'string'? new Firebase(url) : url;
}
但它可能不是那么简单(是什么?),这可能会被限制为只读范围要在两个方向上这项工作将需要相当多的规划和腿部。
感谢您的FirebaseIndex!现在我只是试图单向。我不认为只是设置这个.fref是足够的。传入FirebaseIndex会收到错误消息:'错误:新的Firebase失败:第一个参数必须是有效的Firebase网址,路径不能包含“。”,“#”,“$”,“[”或“]” “试图弄清楚。 – Harry 2013-04-25 23:29:33
Harry,您需要对AngularFire进行修改;上述内容并不意味着是一种就地解决方案,而是一种如何实现自己想要的想法。查看我的编辑。 – Kato 2013-04-26 02:47:51
我确实有工作,非常感谢! – Harry 2013-04-26 02:51:23
只是过滤它们吗? – lucuma 2013-04-25 22:40:27
是的,过滤可能是你最好的选择,没有简单的方法只能获取索引中的那些。或者,您可以为每个故事创建一个angularFire或angularFireCollection的实例。例如:$ scope.storyA = angularFireCollection('https://example.firebaseio.com/stories/storyA'); – Anant 2013-04-25 22:44:25
@lucuma我想让索引工作。这是使用Firebase非常重要的一部分。 – Harry 2013-04-25 23:30:16