当前位置:  开发笔记 > 编程语言 > 正文

Selectize.js使用静态html进行自定义渲染

如何解决《Selectize.js使用静态html进行自定义渲染》经验,为你挑选了1个好方法。

我正在使用辉煌的selectize.js库生成一个有选择组的有吸引力的选择框.这一切都正常,但我不能使用示例页面中的自定义渲染器(电子邮件联系人)http://brianreavis.github.io/selectize.js/,因为"item"不知道"电子邮件"属性.我知道如何在javascript中执行此操作,但如何在静态html中定义这两个属性?

在js中,这个woulde是

$('#id').selectize({
  ...
  options: [
    { name: "Martin", email: "martin@asdf.at" }
  ],
  ....
}

我尝试了以下方法:


但这不起作用......最后从示例中获取渲染函数:

render: {
    item: function(item, escape) {
        return '
' + (item.name ? '' + escape(item.name) + '' : '') + (item.email ? '' : '') + '
'; }, option: function(item, escape) { var label = item.name || item.email; var caption = item.name ? item.email : null; return '
' + '' + escape(label) + '' + (caption ? '' + escape(caption) + '' : '') + '
'; } }

我会感谢任何提示!

此致,马丁



1> Adonias Vasq..:

使用此示例:

var clearhack = $('.selectized').selectize({
    valueField: 'id',
    labelField: 'name',
    searchField: ['name'],
    sortField: 'score',//this is set to 'name' on my version, but seems sortField is only used together with load-function and score-function
    sortDirection: 'desc',
    maxItems: 1,
    //only using options-value in jsfiddle - real world it's using the load-function
    options: [
        {"id":861,"name":"Jennifer","score":6},
        {"id":111,"name":"Jenny","score":6},
        {"id":394,"name":"Jorge","score":6},
        {"id":1065,"name":"Jorge Carlson","score":6},
        {"id":389,"name":"Ann Jennifer","score":3},
        {"id":859,"name":"Bobby Jenkins","score":3},
        {"id":264,"name":"Peter Jenkins","score":3},
        {"id":990,"name":"Fred","score":1},
        {"id":349,"name":"Kal","score":1},
        {"id":409,"name":"Louis","score":1}
    ],
    create: false,
    render: {
        option: function(item, escape) {
            return '
' + 'ID:'+item.id+' ' + 'Name:'+item.name+' ' + 'DEBUG:'+item.score+'' + '
'; } }, score: function(search) { return function(item) { return parseInt(item.score); }; } });


这不回答这个问题
推荐阅读
路人甲
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有