0

非常に単純な環境で動作するコードのチャンクがあります。

これが私の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'

ここに私のテンプレートがあります:

請求書.hbl

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

請求書.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}}

結論として、同じコードをアプリケーションのより深い位置に移動しただけです。Invoices/search_invoicable_product_form.hbl のコードは、App.InvoicesNewController のコードと同様に変更されていません。これは、IndexController 内のコードと同じです。

でもビンディングをなくした

4

1 に答える 1