gpt4 book ai didi

string - ExtJS 如何从字符串动态创建小部件和布局

转载 作者:行者123 更新时间:2023-12-04 04:38:30 24 4
gpt4 key购买 nike

ExtJS 库中是否有可能基于某些字符串表示创建布局?

考虑我有一个服务器调用,它用以下数据填充响应 -
" Ext.create('Ext.Button', {xtype: 'button', text: 'button form server'}); "这实际上是一个有效的 javascript 代码来创建一个按钮(被输入源代码编辑器它创建一个按钮)。

有没有办法获得这样的字符串响应并完全基于该字符串构造 extjs 的按钮?

例如:ajax 的 response.responseText 等于 Ext.create('Ext.Button', {xtype: 'button', text: 'button form server'});。我需要的是一个像 Ext.someMagicStuff(response.responseText) 这样的组件,它理解我传递的字符串并创建一个按钮。

非常感谢您的时间和任何想法!

最佳答案

对于已定义的类型,这并不复杂。只需返回一个有效的配置,如

{xtype: 'button', text: 'button form server'}

作为 JSON 并使用解决答案
Ext.ComponentManager.create(Ext.decode(response.responseText));

componentmanager 会自动查找 xtype 并返回创建的实例

关于string - ExtJS 如何从字符串动态创建小部件和布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19294611/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com