我知道这有点重复,但我创建动态组件渲染器的所有努力都失败了,可能是由于我缺乏对 ember 概念的了解。
我的场景是一个多用途搜索栏,它将搜索缓存中的模型。我希望根据模型的类型键在搜索输入下方呈现每个搜索结果。车把文件将根据模型类型和语法命名components/app-search-<model-type-key>.hbs
例如客户模型的模板名称应该是components/app-search-customer.hbs
我的搜索模板如下所示:
<div class="well well-md">
<div class="input-group">
{{input value=searchTerm class="form-control"}}
</div>
{{#if searchTerm}} <!-- Updating searchTerm causes results to populate with models -->
{{#if results.length}}
<ul class="list-group search-results">
{{#each result in results}}
<!-- todo -->
{{renderSearchComponent model=result}}
{{/each}}
</ul>
{{else}}
Nothing here Captain
{{/if}}
{{/if}}
</div>
我对 renderSearchComponent 帮助器的尝试如下所示:
Ember.Handlebars.registerHelper('renderSearchComponent', function(model, options) {
var modelType = options.model.constructor.typeKey,
componentPath,
component,
helper;
if (typeof modelType === 'undefined') {
componentPath = "app-search-default";
} else {
componentPath = "app-search-" + modelType;
}
component = Ember.Handlebars.get(this, componentPath, options),
helper = Ember.Handlebars.resolveHelper(options.data.view.container, component);
helper.call(this, options);
});
当运行时 options.model 抛出:TypeError: options.model is undefined
另外我还有以下错误:
Error: Assertion Failed: Emptying a view in the inBuffer state is not allowed and should not happen under normal circumstances. Most likely there is a bug in your application. This may be due to excessive property change notifications.
我已经眨了眨眼睛好几个小时了,试图把这件事做好。我所要求的可能吗?
先感谢您。