Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.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
Backbone.js 骨干木偶布局的UI哈希问题_Backbone.js_Marionette - Fatal编程技术网

Backbone.js 骨干木偶布局的UI哈希问题

Backbone.js 骨干木偶布局的UI哈希问题,backbone.js,marionette,Backbone.js,Marionette,在下面的Layout中,我添加了一个CollectionView以在onRender中显示一个选择列表。紧接着,我使用ui散列来启用或禁用视图中的所有控件。这不适用于由新建App.View.Categories生成的选择 应该吗?或者UI哈希在布局中的区域上不起作用 App.View.UploadFile = Backbone.Marionette.Layout.extend({ template: '#upload-file-template', regions:{

在下面的
Layout
中,我添加了一个
CollectionView
以在
onRender
中显示一个选择列表。紧接着,我使用ui散列来启用或禁用视图中的所有控件。这不适用于由
新建App.View.Categories
生成的选择

应该吗?或者UI哈希在
布局中的
区域
上不起作用

App.View.UploadFile = Backbone.Marionette.Layout.extend({
    template: '#upload-file-template',
    regions:{
        category: 'td:nth-child(4)'
    },
    ui:{
        inputs: 'textarea, select, .save'
    },
    onRender: function(){
        this.category.show(
            new App.View.Categories({
                collection: App.collection.categories
            }) // generates the SELECT list
        );

        console.log(this.ui.inputs); // Length 2. Missing select.
        console.log(this.$('textarea, select, .save')); // Length 3

        this.ui.inputs.prop(
            'disabled', (this.model.get('upload_status')!='staged')
        );
    }
});

这应该是你期望的工作方式。牵线木偶源代码中有问题的代码如下:

调用
binduielments()
ui
散列转换为jQuery选择器对象,并在调用
onRender
方法之前调用它

你看到错误了吗?或者选择器只是不返回任何内容,对元素没有影响


更新:

啊!!当然我对你的代码关注不够。在将子视图添加到区域之前,UI元素选择器会出现,这是正确的。我以前从未遇到过这种情况。。。但这似乎是我们想要解决/支持的问题

目前,我建议最好的解决方法是调用'this.binduielments();'在onRender方法的最后。这将迫使ui元素重新绑定到选择器


我还将在github问题列表中添加一个问题,以寻找更好的解决方案。我不知道什么时候才能做到这一点,但这至少会让它出现在需要修复的事情列表上。

没有错误。我在上面添加了一些示例console.log。选择器省略了select,但返回了其他两个元素。正如您在第二个console.log中看到的,相同的选择器包装在$works中。在onRender中添加选择项之前,将绑定这些项。也许在onRender中添加这样的区域不是最佳做法。你还有别的款式可以推荐吗?