문제

My Durandal app uploads files. I've just added a fallback mode for ie8 that doesn't use File. Instead, I create an iframe and append it to document.body, then set its innerHTML to create a form. I move the <input type='file' name='file' id='file' /> to the form in the iframe and submit the form.

This works and the file duly arrives at the server where my handler saves it to disk and generates a response containing the file size.

I have a handler attached to the iframe load event and it fires and obtains the file size.

But after that my Ui behaves as though all event handlers are unbound.

Does anyone recognise these symptoms?

I've noticed that

  • If I do all the above but don't submit the form my UI is unaffected.
  • If I put app.showMessage("load handler"); in the load handler, it runs but the dialog fails to appear and the UI is catatonic
  • If I also put app.showMessage("pre-submit"); immediately prior to submitting the form, I see the load handler message, then the pre-submit message, and the UI is responsive

More information

This is the innerHTML of the iframe document's body, formatted for your convenience but otherwise unaltered.

<form action="ClassicUploadHandler.aspx" enctype="multipart/form-data" method="post">
  <input name="fileID" value="9845ee66-e1e6-4c1c-8305-965a3ccc16ed">
  <input name="file" id="file" style="display: none;" 
         type="file" data-bind="event: {change: chose}">
</form>

Note that the transplanted file input still has a knockout data-bind element. Is it possible that this is the source of an unhandled exception? Durandal is notorious (with me, at any rate) for going catatonic whenever there's an unhandled exception.

If this is the source of the problem then the solution is to un-bind it prior to transplant. Is that possible, and if so how?

도움이 되었습니까?

해결책

Peter, is it possible that ko.cleanNode() will do what you want?

Unbind view model from view in knockout suggests this approach.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top