代码之家  ›  专栏  ›  技术社区  ›  jose

在DisplayField列表模板中打开URL

  •  0
  • jose  · 技术社区  · 8 年前

    我需要构建一个条件来只选择URL;并且只有当单击URL时,窗口才会打开并加载de-url。

    var cars = 'car - Fiat, country - Italy, site - https://www.sencha.com/';
    
    Ext.create('Ext.form.Panel', {
        renderTo: Ext.getBody(),
        width: 450,
        height: 200,
        bodyPadding: 10,
        title: 'Template',
        items: [{
            xtype: 'displayfield',
            fieldLabel: 'Cars',
            name: 'cars',
            renderer: function (value, field) {
                    if (value && value.indexOf(',') > -1) {
                        this.rndTpl = this.rndTpl || new Ext.XTemplate('<div style = "line-height: 150%;' +
                            'margin-left: -25px; margin-top: -12px; cursor: pointer;">' +
                            '<ul><li>{[values.cars.replace(/,/g, "<li/>")]}</li></ul>' +
                        '</div>');
    
                    return this.rndTpl.apply({
                        cars: value
                    });
                } else {
                    return value;
                }
            },
            listeners: {
                render: function(field, eOpts) {
                    field.setValue('car - Fiat, country - Italy, site - https://www.sencha.com/')
                },
                change: function(field){
                       var stringValues = field.value;
    
                       if(stringValues && (stringValues !== '' ||  stringValues !== null)){
    
                           var arrayValues = stringValues.split(',');
    
                           arrayValues.map(function(item){
                             var typeValue =  item.indexOf('site');
    
                            if(typeValue > -1){
                                 var value = item.substring(item.indexOf('-') + 1);
    
                                field.getEl().on('click', function () {
                                     window.open(value, '', false);
                                });
    
                            }else{
                                return false;
                            }
                        });
                    }
               }
             }
         }]
    
      });
    

    https://fiddle.sencha.com/#view/editor&fiddle/2ii0

    1 回复  |  直到 8 年前
        1
  •  1
  •   beso9595 Spring boots    8 年前

    所以我把你的小提琴叉起来换了 click FIDDLE