Extjs如何将html div添加为项目

时间:2019-06-06 14:15:10

标签: html extjs

如何将Traceback (most recent call last): File "temp.py", line 8, in <module> converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir) File "/media/data2/anaconda3/envs/tf-lite/lib/python3.6/site-packages/tensorflow/lite/python/lite.py", line 696, in from_saved_model output_arrays, tag_set, signature_key) File "/media/data2/anaconda3/envs/tf-lite/lib/python3.6/site-packages/tensorflow/lite/python/convert_saved_model.py", line 205, in freeze_saved_mode l frozen_graph_def = util.freeze_graph(sess, in_tensors, out_tensors) File "/media/data2/anaconda3/envs/tf-lite/lib/python3.6/site-packages/tensorflow/lite/python/util.py", line 238, in freeze_graph output_arrays) File "/media/data2/anaconda3/envs/tf-lite/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 324, in new_func return func(*args, **kwargs) File "/media/data2/anaconda3/envs/tf-lite/lib/python3.6/site-packages/tensorflow/python/framework/graph_util_impl.py", line 270, in convert_variable s_to_constants inference_graph = extract_sub_graph(input_graph_def, output_node_names) File "/media/data2/anaconda3/envs/tf-lite/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 324, in new_func return func(*args, **kwargs) File "/media/data2/anaconda3/envs/tf-lite/lib/python3.6/site-packages/tensorflow/python/framework/graph_util_impl.py", line 182, in extract_sub_grap h _assert_nodes_are_present(name_to_node, dest_nodes) File "/media/data2/anaconda3/envs/tf-lite/lib/python3.6/site-packages/tensorflow/python/framework/graph_util_impl.py", line 137, in _assert_nodes_ar e_present assert d in name_to_node, "%s is not in graph" % d AssertionError: ParseExample/ParseExample:3 is not in graph 组件作为子组件放置并使用Exjs进行访问?

这是我尝试过的:

div

此div将具有可编辑的内容。

该代码显示de div,但是,如何设置其样式以及如何访问其内容?另外,是否有Ext.define('mycomponent.mywindow', { extend: 'Ext.window.Window', id: 'mywindow', xtype: 'mywindow', modal: true, bodyPadding: 10, height: 400, width: 575, closeAction: 'destroy', resizable: false, items: [ { html: '<div id="mydiv">Hi there</div>' }, { ... } ], initComponent: function () { this.callParent(arguments); } }); 之类的东西?

1 个答案:

答案 0 :(得分:1)

可以通过两种方式完成。一种是直接使用html源字符串,而另一种是使用Ext.Xtemplate。 Ext.Xtemplate被认为是很好的,因为它可以很好地控制事件,数据以及验证。

这是简单的poc代码:

Ext.application({
    name : 'Fiddle',

    launch : function() {
        //Ext.Msg.alert('Fiddle', 'Welcome to Sencha Fiddle!');
        Ext.Viewport.add({
            xtype: 'panel',
            title: "hello",
            items: [
                {
                    html: `<div contenteditable="true">I am raw implementation</div>`,
                    listeners: {
                        input: {
                            fn: function() {
                                console.log("Changed one")
                            },
                            element: "element",
                            selector: "div"
                        }
                    }
                }, {
                    xtype: "container",
                    data: {
                        initialValue:"I am with template<script>alert(2);</script>"
                    },
                    tpl: `<div id="editor" contenteditable="true">{initialValue:htmlEncode}</div>`,
                    listeners: {
                        click: {
                            fn: function() {
                                console.log("clicked")
                            },
                            element: "element",
                            selector: "#editor"
                        },
                        input: {
                            fn: function() {
                                console.log("Changed two");
                            },
                            element: "element",
                            selector: "#editor"
                        }
                    }
                }]
        })
    }
});

这里正在工作:https://fiddle.sencha.com/#view/editor&fiddle/2srn

由于您尝试构建与dom非常接近的内容,因此可能会遇到XSS问题,因此您会在xtemplate中看到htmlEncode。如果您想在删除其他标签的同时拥有某些标签(我相信这是采用到contenteditor div的用例),请查看https://www.sencha.com/forum/showthread.php?67547-Template-XSS-and-encodeHtml,它说明了如何编写自己的可在Ext中使用的函数。 .XTemplate实例。