2016-02-23 161 views
0

所以我有聚合物1.0的预期并没有传递数组的问题。我现在有一个usersInOrg阵列需要被传递到应用程序的其他部分。自动数据绑定系统的工作原理就像一个魅力,直到我开始尝试用突变从嵌套函数中添加对象的数组。聚合物阵列更新

物业:

usersInOrg: { 
     type: Array, 
     notify: true 
    }, 

功能:

_computeUsersInOrg: function(){ 
    /************* userIdsObjectInOrg *********** 
    { 
     uid: true 
     uid2: true 
     uid3: true 
     ... 
    } 
    ********************************************/ 
    var userIds = Object.keys(this.userIdsObjectInOrg); 
    // Empty old users (just in case) 
    this.usersInOrg = []; 
    // So I can use this.notifyPath or this.usersInOrg in the firebase call 
    var self = this; 
    for (var key in userIds) { 
     // Where the user is found in the database 
     var userRef = this.baseRef + '/users/' + userIds[key]; 
     // Create query 
     var firebaseRef = new Firebase(userRef); 
     // Here is where I should be adding my people into the array 
     firebaseRef.on("value", function(snapshot) { 
     // This comes back fine { name: Jill, age: 23, ... } 
     console.log(snapshot) 

     // For debugging purposes (number are appearing correctly) 
     self.notifyPath('usersInOrg', [5,6]); 
     // Add in the user info to the array 
     self.push('usersInOrg', snapshot.val()); 
     // Let index know I added it 
     self.notifyPath('usersInOrg', self.usersInOrg); 
     }) 
    } 
    } 

输出:

Users in Org: 5,6 
Hello from shokka-admin-homepage 

为什么没有对象附加到我的阵列?它应该输出5,6,[Object object]我会想。

回答

1

当我打字这个问题,我找到了答案。如果我深入了解清单的内容,我可以更好地了解我的内容。这是我的列表看起来像循环虽然并试图显示一些数据。我没有更改我的问题中的任何代码。

新输出:

User: 5 
First Name: 
User: 6 
First Name: 
User: [object Object] 
First Name: Jill 

Users in Org: 5,6 
Hello from shokka-admin-homepage 

这个故事的寓意:数组不字符串化对象以相同的方式对象字符串化自己。当一个对象在一个数组中时,它只是简单地跳过它并继续前进。控制台日志是你的朋友。

控制台日志输出:

[5, 6, Object, splices: Object]