简体   繁体   English

根据一组键/值对生成对话框

[英]Generate a dialog based on a set of key/value pairs

I am working on an already existing UI and I need to do some modifications. 我正在处理现有的UI,我需要做一些修改。 The UI uses freemarker for templating. UI使用freemarker进行模板化。

There is a section in the HTML page which is : HTML页面中有一个部分是:

<td>
    <#if authRole?? && authRole == 'ADMIN' >
    <#if leaf.value??>
    <a href="#" data-toggle="modal" class="href-select" data-target="#addPropertyModal" itemprop="${leaf.strValue?html}" >${leaf.name}</a> 
    <#else>
    <a href="#" data-toggle="modal" class="href-select" data-target="#addPropertyModal" itemprop="" >${leaf.name}</a> 
    </#if>
    <#else>
    ${leaf.name}
    </#if>
</td>

Here clicking on the leaf.name value opens a dialog box which has a Name and Value textbox. 在此处单击leaf.name值将打开一个对话框,其中包含名称和值文本框。 The modal for the dialog is this : 对话框的模式是这样的:

<div class="modal fade" id="addPropertyModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Add Property</h4>
            </div>
            <div class="modal-body">
                <div class="input-group input-group-lg">
                    <span class="input-group-addon">Name</span>
                    <input type="text" id="newProperty"  name="newProperty" class="form-control" placeholder="name">
                    </div>
                    <br/>
                    <div class="input-group input-group-lg">
                        <span class="input-group-addon">Value</span>
                        <textarea id="newValue" name="newValue" class="form-control" placeholder="value" style="resize:vertical;" ></textarea>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <input type="submit" id="savePropertyBtn" name="action" value="Save Property" class="btn btn-primary"/>
                    <input type="submit" id="updatePropertyBtn" name="action" value="Update Property" class="btn btn-primary"/>
                </div>
            </div>
        </div>
    </div>
</div>

This is the js part: 这是js部分:

$(".href-select").click(function() {
                var propName = $(this).text();
                var propVal = $(this).attr('itemprop');
                $("#newProperty").attr('readonly', true);
                $("#newProperty").val(propName);
                $("#newValue").val(propVal);

                $("#savePropertyBtn").hide();
                $("#updatePropertyBtn").show();
            });

Now my problem is I want to return a map instead of a String in leaf.strValue . 现在我的问题是我想在leaf.strValue返回一个地图而不是一个字符串。 And in the dialog bos , instead of this 而在对话框中,而不是这个

Name  : [    ]
Value : [    ]

I want this: 我要这个:

Name : [    ]
Key1 : [Value]
Key2 : [Value]

The Name is the node name and the Value is the node value. Name是节点名称, Value是节点值。 But in my use case , the node Value consists of many values which I have decided to show as a list in the UI. 但在我的用例中,节点Value包含许多值,我决定将其显示为UI中的列表。 So Key1 is the first key in the node Value (which is a map) and [Value] is the value of the corresponding key. 因此Key1是节点Value中的第一个键(它是一个映射), [Value]是相应键的值。

Please help me on this. 请帮帮我。

EDIT: I am ok with making the node value as a JSON string too. 编辑:我也可以将节点值作为JSON字符串。 So in that case , the keys and values should be the key value pairs in the JSON. 因此,在这种情况下,键和值应该是JSON中的键值对。 So I tried this : 所以我尝试了这个:

var json = JSON.parse(propVal, 'UTF-8');

and was able to get the JSON object. 并能够获得JSON对象。 But now I want the dialog box to show the key and value pairs through iteration ( because the key value pairs are not fixed ). 但现在我希望对话框通过迭代显示键和值对(因为键值对不是固定的)。

Well, you need, instead of the <div><span>Value</span><-input_field-/></div> block, to generate, this way or another, a series of such blocks according to your keys/values. 那么,您需要,而不是<div><span>Value</span><-input_field-/></div>块,以这种方式生成一系列这样的块,根据您的键/值。 And probably handle them in the JS in the similar "array" manner. 并且可能以类似的“数组”方式在JS中处理它们。

Otherwise, I cannot say anything since you told nothing about the form and shape of this mysterious key/value data set. 否则,我不能说什么,因为你没有说出这个神秘的键/值数据集的形式和形状。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM