Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$bindAsArray don't update binded data dynamically #19

Closed
monocles opened this issue Jun 25, 2016 · 4 comments · Fixed by #22
Closed

$bindAsArray don't update binded data dynamically #19

monocles opened this issue Jun 25, 2016 · 4 comments · Fixed by #22

Comments

@monocles
Copy link

monocles commented Jun 25, 2016

I'm trying to bind a child node dynamically after the event changes.

...
var db = firebaseApp.database().ref('data/')

new Vue({
  el: '#app',
  data: {
    current: 'first',
    currentNode: []
  },
  firebase: {
    myArray: db
  },
  ready() {
    this.$bindAsArray('currentNode', db.child(this.current))
  },
  watch: {
    'curent': function(node) {
      console.log(node)
      this.$bindAsArray('currentNode', db.child(this.current))
    }
  },
  methods: {
    pushToNode() {
        this.$firebaseRefs.currentNode.push({
          hello: 'hello',
          world: 'world'
        })
      }
  }
})

and I expect to receive data at the output on binded array like this:
<pre>{{ currentNode | json }}</pre>

I have made 2 fiddle examples
First with $bindAsArray which does not update the state after the event triggering.
https://jsfiddle.net/tpq0x7zu/1/

And second one with $bindAsObject which updates the data after the child node changes.
https://jsfiddle.net/f95a1zwx/5/

@monocles monocles changed the title $bindAsArray does not bind data dynamically $bindAsArray don't update binded data dynamically Jun 25, 2016
@monocles
Copy link
Author

Ok. solve this with vue.filter

Vue.filter('getCurrent', function (value, key) {
  let v = []
  value.filter(function(item) {
    if(item['.key'] === key) {
     v = item
    }
  })
  return v
})

@lunardog
Copy link

I'm having the same issue. Tried this.$unbind and bind again, but no good.

@lunardog
Copy link

lunardog commented Jun 29, 2016

The reason was on Vue side of vuefire. Fixed by deleting the reactive property in $bindAsArray, added test.

See PR: 5d5fe2a

posva added a commit to posva/vuefire that referenced this issue Jul 29, 2016
@posva posva mentioned this issue Jul 29, 2016
posva added a commit to posva/vuefire that referenced this issue Jul 31, 2016
posva added a commit to posva/vuefire that referenced this issue Jul 31, 2016
posva added a commit to posva/vuefire that referenced this issue Jul 31, 2016
posva added a commit to posva/vuefire that referenced this issue Jul 31, 2016
@mrcsmcln
Copy link

mrcsmcln commented Sep 1, 2016

I am having a similar issue. The following code fails to display a JSON representation of foo:

<div id="app">{{ foo | json }}</div>
new Vue({

    el: '#app',

    ready() {
        this.$bindAsArray('foo', db.ref('foo').orderByChild('bar').equalTo('baz');
    }

})

Is this thought to be caused by the same error?

Edit: Here's the prettiest temporary solution I've been able to find:

new Vue({

    el: '#app',

    ready() {
        this.$bindAsArray('_foo', db.ref('foo').orderByChild('bar').equalTo('baz');
        this.foo = this._foo;
    },

    data() {
        return {
            foo: null
        }
    }

});

@posva posva closed this as completed in #22 Sep 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants