jsviews - 如何为 {{selectmenu}} 标签中的选项指定自定义渲染模板
问题描述
我正在寻找一个可以为渲染选项指定模板的示例,以便我可以将选项渲染为两部分:具有背景颜色和值的跨度。
类似于此https://jqueryui.com/selectmenu/#custom_render
这在 jsviews 标签实现中是否支持?
非常感谢。
解决方案
可能还有其他方法,包括制作您自己的自定义标签 - 不使用 jQuery UI,或在此处{{selectmenu}}
创建标签控件的派生版本(使用baseTag)。{{myselectmenu}}
但这里有一个快速的建议,你可以做到这一点:
{^{selectmenu person name="person" onBind=~onbind}}
{^{for people}}
<option data-style="{{:style}}" value="{{:id}}">{{:name}}</option>
{{/for}}
{{/selectmenu}}
数据:
people: [
{name: "John Resig", id: "1", style: "background-image: url(...);"},
...
代码:
pageTmpl.link("#page", model, {
onbind: function(val) {
// override onBind for this tag control instance
this.baseApply(arguments);
// override _renderItem for this widget instance:
this.widget._renderItem = function( ul, item ) {
var li = $( "<li>" ),
wrapper = $( "<div>", { text: item.label } );
if ( item.disabled ) {
li.addClass( "ui-state-disabled" );
}
$( "<span>", {
style: item.element.attr( "data-style" ),
"class": "ui-icon " + item.element.attr( "data-class" )
})
.appendTo( wrapper );
return li.append( wrapper ).appendTo( ul );
};
}
});
推荐阅读
- c# - IQueryable 如何创建实体实例以及如何捕获它
- javascript - 三.js 三.交互 三.transformControls
- login - 尝试使用 FTP 连接时出现 503 错误,它在过去 3 年中一直在工作,没有进行任何更改
- featuretools - 无法在功能工具中建立关系
- airflow - 如何从 python 脚本调用 Dag
- dart - 修改 sqflite 表后,应用程序将崩溃
- r - 不使用包的条形图
- python - 如何在“Matplotlib”中使用 xy 参数?
- swift - NSScrollView 是如何实现这样的内容视图的呢?
- c# - 当字节数组的源是 jpg 时,从存储的字节数组创建位图并保存到磁盘会引发 GDI+ 异常