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

1.0.0-rc1: v-for + filters + .sync does not work as expected #1433

Closed
karevn opened this issue Oct 16, 2015 · 8 comments
Closed

1.0.0-rc1: v-for + filters + .sync does not work as expected #1433

karevn opened this issue Oct 16, 2015 · 8 comments

Comments

@karevn
Copy link

karevn commented Oct 16, 2015

This fiddle: http://jsfiddle.net/kyhqq375/ is expected to change "Items: one, two" when clicking buttons, but "write" filter is never called, and "one, two" is never changed. Obviously, not a simple use case, but it should work or at least show a warning...

@marcvdm
Copy link

marcvdm commented Oct 16, 2015

I was "fiddling" around in your jsfiddle and got the following error
[Vue warn]: It seems you are using two-way binding on a v-for alias, and the v-for has filters. This will not work properly. Either remove the filters or use an array of objects and bind to object properties instead.

The result of the filter is not bound to the current vm so there can't be a 2 way bind.

There are better ways to solve the problem that you are facing
http://jsfiddle.net/kyhqq375/1/

@karevn
Copy link
Author

karevn commented Oct 16, 2015

@marcvdm that is exactly how I worked it around in my app, but it still is a workaround, not a solution.

Btw, the warning does not show in my fiddle. You replaced item.value binding expression with item, which generates the warning.

@karevn
Copy link
Author

karevn commented Oct 16, 2015

Hmm. I think, a watcher should be created with "deep" option to fix it (instead of "shallow" watcher). Am I right?

@yyx990803
Copy link
Member

This is a use case that is by design not going to work. "deep" has nothing to do with this. Two-way bindings on a filtered copy doesn't really make sense. I anticipated cases like this but your usage somehow bypassed the warning check ;)

It will give a warning in such scenarios now.

@karevn
Copy link
Author

karevn commented Oct 17, 2015

@yyx990803 may be there's still some kind of a solution for this? I think it's possible to deep-watch for changes in the filtering result, and then run the write filter to re-assign the initial value.

@karevn
Copy link
Author

karevn commented Oct 17, 2015

@yyx990803 and I don't see reasons (other than code complexity) why should not it work. I think of it the next way: We have an initial object, which is passed through a filter to build a new one (or an array), which is then iterated by v-for. If filter results are changed, then we run the write filter to re-build the initial value (which is not always possible, but it's an app-specific detail). It's just a "streamlined" version of @marcvdm 's workaround, IMO.

@yyx990803
Copy link
Member

Yes, this is a marignally useful feature that involves a lot of code complexity - maybe requires rewriting some parts of how filters work. Although theoretically it "should" work, given the limited time I have I don't see it ever become a priority in the foreseeable future. You are free to investigate and submit a PR if you feel it's worth the effort.

@karevn
Copy link
Author

karevn commented Oct 17, 2015

Okay, i'll look for a solution for this thing.
17 окт. 2015 г. 20:21 пользователь "Evan You" notifications@github.com
написал:

Yes, this is a marignally useful feature that involves a lot of code
complexity - maybe requires rewriting some parts of how filters work.
Although theoretically it "should" work, given the limited time I have I
don't see it ever become a priority in the foreseeable future. You are free
to investigate and submit a PR if you feel it's worth the effort.


Reply to this email directly or view it on GitHub
https://github.com/yyx990803/vue/issues/1433#issuecomment-148923739.

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

No branches or pull requests

3 participants