2013-05-13 67 views
0

我有一段代碼,這是一個非常簡單的環境中工作:ember.js:我綁定在一個環境中工作,但不是在另一個

這裏是我的index.hbl

{{view App.SearchInvoicableProductFormView}} 

這裏我的看法

App.SearchInvoicableProductFormView = Em.View.extend 
    templateName: 'search_invoicable_product_form' 
    invoicableSearch: "Search..." 

這裏是我的模板search_invoicable_product.hbl

{{view Ember.TextField valueBinding="invoicableSearch" size="8"}}<br /> 
{{#each invoicable in results}} 
{{invoicable.name}}<br /> 
{{/each}} 

,這裏是我的控制器:

App.IndexController = Ember.Controller.extend 
    invoicableSearch: "Cerca..." 

    results: (-> 
    if @get("invoicableSearch").length > 3 
     App.Invoicable.find(q: @get("invoicableSearch")) 
).property("invoicableSearch") 

在這種情況下一切工作正常。當我輸入的東西進入我的文本字段中執行搜索


雖然在這種情況下綁定不起作用:

我在路徑:invoices/new

這裏是我的路由器:

App.Router.map -> 
    @resource "invoices", -> 
    @route 'new' 

這裏是我的路線:

App.InvoicesRoute = Ember.Route.extend 
    model: -> App.Invoice.find() 

App.InvoicesNewRoute = Ember.Route.extend 
    model: -> 
    App.Invoice.createRecord() 

這裏是我的控制器:

App.InvoicesNewController = Ember.ObjectController.extend 
    invoicableSearch: "Search..." 

    results: (-> 
    if @get("invoicableSearch").length > 3 
     App.Invoicable.find(q: @get("invoicableSearch")) 
).property("invoicableSearch") 

這裏是我的觀點:

App.InvoiceRowFormView = Em.View.extend 
    templateName: "invoices/invoice_row_form" 

App.SearchInvoicableProductFormView = Em.View.extend 
    templateName: 'invoices/search_invoicable_product_form' 

ANS這裏是我的模板:

invoices.hbl

{{#each controller}} 
... 
{{/each}} 
{{outlet}} 

invoice.hbl

<form> 
{{partial 'invoices/form'}} 
</form> 

發票/ form.hbl

...form for invoice... 
{{partial 'invoices/invoice_rows'}} 

發票/ invoice_rows.hbl

{{#each invoiceRows}} 
{{view App.InvoiceRowFormView}} 
{{/each}} 

發票/ invoice_row_form.hbl

... 
{{view App.SearchInvoicableProductFormView}} 
... 

發票/ search_invoicable_product_form.hbl

{{view Ember.TextField valueBinding="invoicableSearch" size="8"}}<br /> 
{{#each invoicable in results}} 
{{invoicable.name}}<br /> 
{{/each}} 

總而言之:我只是將相同的代碼放到了更深的位置,進入我的應用程序。發票/ search_invoicable_product_form.hbl的代碼不會改變,就像代碼到App.InvoicesNewController中一樣,它與IndexController中的代碼相同。

但我失去了我的綁定

回答

0

你需要沿着控制器每個視圖通過,我想。試試這個:

{{#each invoiceRows}} 
    {{view App.InvoiceRowFormView controllerBinding="this"}} 
{{/each}} 
+0

東西已經改變。我可以在我的搜索框中看到「搜索...」佔位符,當我創建html塊時綁定一次激發,但當我更改屬性 – 2013-05-14 08:14:10

+0

時,它不起作用!問題是一些html塊被創建,然後移動到dom中的另一個地方。我覺得燼不喜歡它! – 2013-05-14 13:44:49