2011-09-23 102 views
1

在我的应用程序主页上,我构建了一个“Widgets”系统。小部件的来源是在服务器端生成的,并通过Ajax推送到客户端。从Ajax请求执行内联脚本

Ext.Ajax.request({ 
    url: '/get-widgets', 
    success: function(response) { 
     var boxes = Ext.decode(response.responseText); 
     Ext.each(boxes, function(box) { 
      box.id = 'cell-' + box.cell; 

      var element = Ext.DomHelper.append('canvas', { 
       tag: 'div', 
       id: box.id, 
       cls: 'widget size-' + (box.size || '11'), 
       children: [{ 
        tag: 'div', 
        cls: 'title', 
        html: box.title 
       }, { 
        tag: 'div', 
        cls: 'main', 
        html: box.body 
       }] 
      }, true); 
     }); 
    } 
}); 

的问题是,一些小部件有一些内嵌的JavaScript在自己的身体,需要被执行。这在Firefox中完美工作,但不在Chrome中。

是否有一个标志或您需要激活的内嵌代码执行?

回答

1

找到Ext.Element::update()方法的特点是扫描并执行内联脚本的标志。我改变我的代码如下,以利用此方法:

var element = Ext.DomHelper.append('canvas', { 
    tag: 'div', 
    id: box.id, 
    cls: 'widget size-' + (box.size || '11') + ' ' + (box.cls || '') + ' ' + (box.type || ''), 
    children: [{ 
     tag: 'div', 
     cls: 'title', 
     html: box.title 
    }, { 
     id: box.id + '-body', 
     tag: 'div', 
     cls: 'main' 
    }] 
}, true); 

Ext.get(box.id + '-body').update(box.body, true);