Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 如何通过AngularFire$asObject或$asArray返回特定的项目列表_Angularjs_Firebase_Angularfire - Fatal编程技术网

Angularjs 如何通过AngularFire$asObject或$asArray返回特定的项目列表

Angularjs 如何通过AngularFire$asObject或$asArray返回特定的项目列表,angularjs,firebase,angularfire,Angularjs,Firebase,Angularfire,我正在尝试学习Firebase AngularFire,使用新方法$asObject或$asArray,以及博客文章中推荐的数据结构 假设我有列表和项目的数据,我想返回特定列表中包含的所有项目 FIREBASE根目录:有两个位置:1)列表,2)项目 这是我的密码: <html ng-app="appListsOfItems"> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularj

我正在尝试学习Firebase AngularFire,使用新方法$asObject或$asArray,以及博客文章中推荐的数据结构

假设我有列表和项目的数据,我想返回特定列表中包含的所有项目

FIREBASE根目录:有两个位置:1)列表,2)项目

这是我的密码:

<html ng-app="appListsOfItems">
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.19/angular.min.js"></script>
    <script src="https://cdn.firebase.com/js/client/1.0.21/firebase.js"></script>
    <script src="https://cdn.firebase.com/libs/angularfire/0.8.2/angularfire.min.js"></script>  
</head>

<body ng-controller="myCtrl">

<h1>Lists of Items</h1>
<b>Write out the title of this list: </b>
<div ng-model="list">{{list.listtitle}}</div>

<b>Write each of the itemids for this list - (isonlist):</b>
<div ng-repeat="(lid, li) in list.listitems">
{{lid}} | {{li}}
</div>

<b>Write the itemname for each of the items for this list:</b>
<div ng-repeat="(iid, i) in items">
{{iid}} | {{i.$id}} | {{i.itemname}}
</div>

<script>
    var app = angular.module("appListsOfItems", ["firebase"]);

    app.controller("myCtrl", 
        function($scope, $firebase) {

            // Create firebase reference to a specific list 'listid3'
            var listRef = new Firebase("https://xxxxx.firebaseio.com/lists/listid3");

            // Assign the firebase reference to an angularfire object using the new $asObject method
            var objList = $firebase(listRef).$asObject();
            //Bind the object to scope and give it a name using the new $bindTo method
            objList.$bindTo($scope, "list");
            console.log(objList);

            // Get the item name of each of the items on the list 'listid3'
            // !!! THIS IS NOT WHAT I WANT. THIS RETURNS ALL ITEMS.
            var refItems = new Firebase("https://xxxxx.firebaseio.com/items");
            var arrayItems = $firebase(refItems).$asArray();
            $scope.items = arrayItems;
            console.log(arrayItems);

        }
    );

</script>
</body>
</html>

项目清单
写出此列表的标题:
{{list.listtitle}
写入此列表的每个ItemId-(isonlist):
{{lid}}{{li}
为此列表中的每个项目写入itemname:
{{iid}}{{i.$id}}{{i.itemname}}
var app=angular.module(“appListsOfItems”[“firebase”]);
app.controller(“myCtrl”,
函数($scope$firebase){
//创建特定列表“listid3”的firebase引用
var listRef=新Firebase(“https://xxxxx.firebaseio.com/lists/listid3");
//使用新的$asObject方法将firebase引用指定给angularfire对象
var objList=$firebase(listRef)。$asObject();
//将对象绑定到作用域,并使用新的$bindTo方法为其命名
对象列表$bindTo($scope,“list”);
控制台日志(objList);
//获取列表“listid3”中每个项目的项目名称
//!!!这不是我想要的。这将返回所有项目。
var=新的火基(“https://xxxxx.firebaseio.com/items");
var arrayItems=$firebase(重新安装)。$asArray();
$scope.items=arrayItems;
控制台日志(arrayItems);
}
);
该代码呈现:

项目清单

写出此列表的标题:

ListC

写入此列表的每个ItemId-(isonlist):

项目ID1 |正确

项目ID2 |正确

为此列表中的每个项目写入itemname:

0 | itemid1 | itemA

1 |项目ID2 |项目B

2 |项目ID3 |项目C

3 |项目ID4 |项目D

===========================================

问题:$scope.items=arrayItems返回“items”位置中的所有项

问题:如何为仅包含在“listid3”中的项目写出“itemname”

例外结果(写出列表“listid3”中每个项目的项目名称):

0 | itemid1 |itemA


1 | itemid2 |itemB

您正在尝试连接两个数据位置:
列表
项目

Firebase中没有内置的对此类连接的支持,AngularFire中也没有返回子集的数组

您必须自己编写(例如使用
一次
来检索列表中的每个项目)或从Kato的Firebase util库中使用
加入


另请参见“”部分,其中涵盖了相同的主题。

右侧:不能执行连接。我担心我的结构一开始就错了。我真的很挣扎。在经历了一辈子的SQL思考之后,我很难再去想它了。我最终会得到它的。谢谢你的帮助。
<html ng-app="appListsOfItems">
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.19/angular.min.js"></script>
    <script src="https://cdn.firebase.com/js/client/1.0.21/firebase.js"></script>
    <script src="https://cdn.firebase.com/libs/angularfire/0.8.2/angularfire.min.js"></script>  
</head>

<body ng-controller="myCtrl">

<h1>Lists of Items</h1>
<b>Write out the title of this list: </b>
<div ng-model="list">{{list.listtitle}}</div>

<b>Write each of the itemids for this list - (isonlist):</b>
<div ng-repeat="(lid, li) in list.listitems">
{{lid}} | {{li}}
</div>

<b>Write the itemname for each of the items for this list:</b>
<div ng-repeat="(iid, i) in items">
{{iid}} | {{i.$id}} | {{i.itemname}}
</div>

<script>
    var app = angular.module("appListsOfItems", ["firebase"]);

    app.controller("myCtrl", 
        function($scope, $firebase) {

            // Create firebase reference to a specific list 'listid3'
            var listRef = new Firebase("https://xxxxx.firebaseio.com/lists/listid3");

            // Assign the firebase reference to an angularfire object using the new $asObject method
            var objList = $firebase(listRef).$asObject();
            //Bind the object to scope and give it a name using the new $bindTo method
            objList.$bindTo($scope, "list");
            console.log(objList);

            // Get the item name of each of the items on the list 'listid3'
            // !!! THIS IS NOT WHAT I WANT. THIS RETURNS ALL ITEMS.
            var refItems = new Firebase("https://xxxxx.firebaseio.com/items");
            var arrayItems = $firebase(refItems).$asArray();
            $scope.items = arrayItems;
            console.log(arrayItems);

        }
    );

</script>
</body>
</html>