问题
I'm working on an app that utilizes an observable array to present an editable table of userID information. The app works fantastic in Chrome, but I'm having issues getting it to work with Firefox. For my purposes, these two browsers are the only ones that I care about for now.
I'm using the "click to edit" functionality through the hasfocus
binding in knockout, and it works great with Chrome. Whenever the username is selected, it becomes editable, a save button presents itself, and upon clicking "Save" the info is posted as a JSON string. Firefox doesn't seem to get far enough in the process to post, and it behaves strangely when focus is removed.
There is quite a bit of code so I've prepared this Fiddle to show the problem. Chrome works fine, Firefox not so much.
http://jsfiddle.net/stevehnh/GNssr/
Thanks for any help at all! Hopefully it's something small I'm missing.
回答1:
After fiddling with this for a while, I discovered that the problem was Firefox removing focus from the edit field before I was able to click the "Save" button. In order to get around that, I used the knockout throttle extension.
I used throttle
to add a 400ms wait time before the editing
binding was updated to false
. This also seemed to fix the issue with Firefox displaying both the new text and input field at the same time. I've pasted the offending line, and the updated fiddle below:
editing: ko.observable(false).extend({ throttle: 400 }),
http://jsfiddle.net/stevehnh/GNssr/2/
来源:https://stackoverflow.com/questions/14482199/hasfocus-binding-issues-with-firefox