Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.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 使用主干.Notifier显示自定义视图_Backbone.js_Backbone Views - Fatal编程技术网

Backbone.js 使用主干.Notifier显示自定义视图

Backbone.js 使用主干.Notifier显示自定义视图,backbone.js,backbone-views,Backbone.js,Backbone Views,我使用的是显示警报。如何在其中显示自定义主干视图? 有什么建议吗?不要认为它适合添加您自己的自定义视图。通知视图的定制是通过CSS实现的 对于自定义按钮,可以使用css属性: buttons: [ {'data-role': 'myOk', text: 'Sure', 'class': 'default', css: {width: 120}}, {'data-role': 'myOk', text: 'Yes'}] 要自定义基本通知窗口,请使用“notifier”CSS类 您

我使用的是显示警报。如何在其中显示自定义主干视图?
有什么建议吗?

不要认为它适合添加您自己的自定义视图。通知视图的定制是通过CSS实现的

对于自定义按钮,可以使用css属性:

buttons: [
    {'data-role': 'myOk', text: 'Sure', 'class': 'default', css: {width: 120}},
    {'data-role': 'myOk', text: 'Yes'}]
要自定义基本通知窗口,请使用“notifier”CSS类

您可以使用通知程序上的“baseCls”属性更改此设置

不幸的是,我不认为有一种方法可以将主干视图分配给通知程序,但是如果只是定制您想要的美学效果,那么希望CSS就足够了


如果你真的想采用一种黑客方法,你可以使用NotificationView,它是一个标准的主干视图(Notifier类的一部分-Backbone.Notifier.NotificationView)。您可以尝试将其覆盖到您的实现中,但这肯定是一种黑客行为,因此不推荐使用它。值得一看notifer.js源代码。

要在backbone.notifier中显示我的自定义视图,我将在插件中添加以下行

var notifier = new Backbone.Notifier({
            el : 'body',
            theme : 'clean'
        });

notifier.notify({
    custView : (new SomeView({
          x : 'xyz'
        })),
    ms : false,  //to aviod a timeout 
    destroy : true 
})
在return语句之前的notify函数中

    .......

    if(options.custView){
        msgInner.off('click'); //the turn off default behaviour which is to destroy view on click
        options.custView.destroyNotifier = removeFn; //now in the custom view i just call this.destroyNotification to destroy the notification 
        msgView.$el.find('.notifier-message').html(options.custView.render().el); //pasting my view on notification to display  
    }                   
    return msgView;
}
这就是我现在所说的插件

var notifier = new Backbone.Notifier({
            el : 'body',
            theme : 'clean'
        });

notifier.notify({
    custView : (new SomeView({
          x : 'xyz'
        })),
    ms : false,  //to aviod a timeout 
    destroy : true 
})

我想从我的应用程序中删除bootbox插件,我目前使用它来显示自定义视图并完全使用主干通知程序。我知道没有选项可以向该插件传递视图。我可以在插件中进行任何黑客操作以实现此功能在通知程序类中有NotificationView,这是一个标准主干视图,您可以尝试覆盖它这是你的实现,但它肯定是一个黑客,我不会推荐它。我会在答案中添加注释,值得查看notifier.js源代码。我使用它似乎没有任何问题。有任何反馈或更好的方法吗