我有一大堆代码在非常简单的环境中工作:
这是我的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'
这里是我的模板:
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 :(得分:0)
我认为你需要将控制器传递给每个视图。试试这个:
{{#each invoiceRows}}
{{view App.InvoiceRowFormView controllerBinding="this"}}
{{/each}}