add_view_button
- add_view_button(text, options)
使用范围: client
编程语言: javascript
描述说明
使用 add_view_button ,可以在视图表单窗体上动态地添加一个按钮。
在 on_view_form_created 事件中经常使用这个方法。
下列参数被传给这个方法:
text- 将在按钮上显示的文本内容。options- 指定按钮额外属性的选项。
options 参数是一个对象,他又下列属性:
parent_class_name是其父元素的一个样式类的名称,默认值是 “form-footer” 。btn_id- 按钮的 ID 属性。btn_class- 按钮的样式类。type- 指定按钮的类型(颜色),其值在下列文本值中:primary
success
info
warning
danger
image- 一个图标样式类, 取值来自 Glyphicons 的图标样式库 http://getbootstrap.com/2.3.2/base-css.htmlsecondary: 如果设置这个属性为 true ,那么在设置了 视图表单窗体 的 按钮置顶(Buttons on top) 属性时按钮将右对齐显示,否则将左对齐显示。expanded- 如果设置为 true ,按钮将具有类 “expanded btn” , 并将其最小宽度定义为 120px,默认为 true .
该方法返回按钮的一个 JQuery 对象。
Examples
function on_view_form_created(item) {
var btn = item.add_view_button('Select', {type: 'primary'});
btn.click(function() {
item.select_records('track');
});
}
function on_view_form_created(item) {
if (!item.view_form.hasClass('modal')) {
var print_btn = item.add_view_button('Print', {image: 'icon-print'}),
email_btn = item.add_view_button('Send email', {image: 'icon-pencil'});
email_btn.click(function() { send_email() });
print_btn.click(function() { print(item) });
}
}