Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript CollectionView中的EmberJS和Handlerbars帮助程序_Javascript_Ember.js_Handlebars.js - Fatal编程技术网

Javascript CollectionView中的EmberJS和Handlerbars帮助程序

Javascript CollectionView中的EmberJS和Handlerbars帮助程序,javascript,ember.js,handlebars.js,Javascript,Ember.js,Handlebars.js,我尝试使用集合视图,在每个项目视图中使用handlerbars帮助器,但我无法使用帮助器函数将路径扩展到值中 Ember.CollectionView.create({content: App.AController, itemViewClass: App.ItemView }); Em.Handlebars.registerHelper('editable', function (path, options) { options.hash.valueBinding = path

我尝试使用集合视图,在每个项目视图中使用handlerbars帮助器,但我无法使用帮助器函数将路径扩展到值中

Ember.CollectionView.create({content: App.AController,
    itemViewClass: App.ItemView
});
Em.Handlebars.registerHelper('editable', function (path, options) {
    options.hash.valueBinding = path;
    return Em.Handlebars.helpers.view.call(this, App.EditField, options);
});
<script type="text/x-handlebars" data-template-name="edit-field">
    {{#if isEditing}}
        {{view Ember.TextField valueBinding = "value" propagatesEvents = true}} 
    {{else}}
        {{#if value}}
            {{value}}
        {{else}}
            <span class="no-name">empty</span>
        {{/if}}
    {{/if}}
</script>
<script type="text/x-handlebars" data-template-name="item-view">
    {{view.content.name}}
    {{editable view.content.name}}
</script>
Ember.CollectionView.create({content:App.AController,
itemViewClass:App.ItemView
});
Em.handlebar.registerHelper(“可编辑”,功能(路径,选项){
options.hash.valueBinding=路径;
返回Em.handlebar.helpers.view.call(此,App.EditField,选项);
});
{{#如果是编辑}
{{view Ember.TextField valueBinding=“value”propertisevents=true}
{{else}
{{{#如果值}}
{{value}}
{{else}
空的
{{/if}
{{/if}
{{view.content.name}
{{可编辑视图.内容.名称}

带有完整的代码示例。

视图上有“IsEdit”属性,但collectionView itemView的上下文是该视图的内容。为了在模板中引用视图上的属性,必须以“view”开始属性路径,如“view.isEditing”中所示


我在你的提琴中做了这样的更改,这个例子似乎和我预期的一样有效。

这并没有扩展“{editable view.content.name}”中的值,{{{view.content.name}在哪里。哦,我真傻,未正确设置上下文,因为您的collectionview是在手动实例化collectionview并附加它时生成的。因此上下文不存在(或者在某些情况下设置为“窗口”,这完全不是我们想要的)试试大小。或者,你可以将contextBinding:“content”添加到ItemView“view preserves context”(一个古老的可切换选项,现在是默认选项)的思想是,无论你的视图继承权有多远,除非你手动更改视图的上下文(例如使用#with),否则它不会更改。因此,从理论上讲,您应该能够在层次结构中有一个vew 3或4,它引用并绑定到itemView的content属性上的属性,就像您位于itemView层次结构的最顶端一样。当然,这首先取决于有一个合适的上下文!