2013-03-21 97 views
1

我試圖完成的結果是,當用戶點擊一個鏈接內聯fancybox用html打開它。當用戶輸入一個值並點擊輸入時,它應該更新(敲除)我的視圖模型,並且該花式框應該面對一個方法。Fancybox與淘汰賽後重新綁定

這是我的代碼到目前爲止,我知道我需要重新申請mybindings,但無法弄清楚如何。

HTML:

<div style="display:none"> 
     <div id="inlineManufacturerAdder"> 
      <div style="width:1000px;"> 
       <!-- In deze div alle content --> 
       <h2>Add new Manufacturer2</h2> 
       <p> 

        <form data-bind="submit: vm.addManufacturer"> 
         <input type="text" data-bind="value: vm.newManufacturer, valueUpdate: 'afterkeydown'" placeholder="New Manufacturer"> 
        </form> 
       </p> 
      </div> 
     </div> 
    </div> 

使用Javascript(打字稿):

export function viewAttached() { 
    $("a.fancybox-link-add-manufacturer").click(function (e) { 
     $.fancybox({ 
      content: $('#inlineManufacturerAdder').html(), //this is where it goes wrong, it gets the content and forgets the bindings I guess! 
      type: 'html' 
     }); 
     return false; 
    }); 
} 

如果我使用DIV(也被設置爲顯示:無)在一個正常的方式,使沒有的fancybox一切正常正好。

我該怎麼辦?我正在使用杜蘭達!

+0

我知道我沒有回答你的問題,但是,爲什麼你要使用fancybox? Durandal具有顯示模式對話框的功能,甚至包含顯示如何更改方面的文檔(http://durandaljs.com/documentation/Showing-Message-Boxes-And-Modals/),你需要什麼從fancybox,可以杜倫達爾會做什麼? – 2013-03-21 13:08:02

回答

1

您不應該需要重新應用綁定。只是不要傳入innerHTML內容,而是將元素節點(或jQuery實例)傳遞給花式框。

EG:相反的:

content: $('#inlineManufacturerAdder').html()

只是做:

content: $('#inlineManufacturerAdder')

[更新]

或東西長這些行:

<a href="#inlineManufacturerAdder" class="fancybox-link-add-manufacturer" >Click me</a> 
<div id="inlineManufacturerAdder" data-bind="html: msg"></div> 

<script> 
$(".fancybox-link-add-manufacturer").fancybox(); 
</script> 

示例:http://jsfiddle.net/r83XF/2/

+0

如果我這樣做,我的打字稿不再編譯。它說:提供的參數不匹配呼叫目標的任何簽名。 http://postimg.org/image/wu0rfagd3/ – 2013-03-21 11:29:36

+0

好的,我已經使用其他解決方案更新了我的帖子。 – badsyntax 2013-03-21 11:53:40

+0

對不起,沒有做到這一點,因爲如果鏈接有href它的sents回到家裏! - > http://stackoverflow.com/questions/15503981/single-page-application-and-inline-fancybox-not-working-properly – 2013-03-21 12:48:18