我正在使用Backbone.Notifier来显示警报。如何在其中显示自定义backbone视图?有什么建议吗?
发布于 2012-11-26 18:20:41
我不认为它适合添加您自己的自定义视图。通知视图的自定义是通过CSS实现的。
对于自定义按钮,可以使用css属性:
buttons: [
{'data-role': 'myOk', text: 'Sure', 'class': 'default', css: {width: 120}},
{'data-role': 'myOk', text: 'Yes'}]要自定义基本通知窗口,请使用'notifier‘CSS类。
您可以使用通知程序上的“baseCls”属性来更改此设置。
不幸的是,我不认为有一种方法可以将主干视图分配给通知程序,但如果只是定制您想要的美学,那么希望CSS就足够了。
如果你真的想采用一种老套的方法,你可以使用NotificationView,它是一个标准的Backbone View (通告程序类--Backbone.Notifier.NotificationView的一部分)。您可以尝试将其覆盖到您的实现中,但这绝对是一个技巧,所以我不建议您这么做。值得一看的是notifer.js的源代码。
发布于 2012-11-27 17:44:10
为了在backbone.notifier中显示我的自定义视图,我在插件中添加了以下几行
在返回语句之前的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
})https://stackoverflow.com/questions/13560548
复制相似问题