所以我遇到了 Polymer 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]
我想。