0

在 Dynamics-365 客户门户网站中,我创建了一个网页,该网页基本上将显示在客户帐户下的网格中安装的所有资产。

为此,我创建了一个实体列表,它有 6 个要呈现的视图。

出于某些客观目的,我需要将列名(我在下面给定的代码中计算)传递给 javascript 函数。如果我更改视图并单击下载按钮,那么它应该将列名传递给函数。

但唉,我每次都只得到空字符串。有没有办法解决这个问题?

页面的骨架如下:

{% assign data = "" %}
{% assign columns = "" %} // columns will come from a dynamic configuration

{% entitylist id:page.adx_entitylist.id %}
    <div class="navbar navbar-default">
        <a href="#" title="Download" onclick="downloadAssets('{{data}}')" >Download</a>
    </div>
    <div>
        <ul class="dropdown-menu" role="menu">
            {% for view in entitylist.views -%}
                {% assign view_name = view.name | split: '-' %}
                <li{% if params.view == view.id %} class="active"{% endif %}>
                   <a href="{{ request.path | add_query:'view', view.id }}">{{view_name.last}}</a>
                </li>
            {% endfor -%}
        </ul>
    </div>

    {% entityview id:viewid, search:params.search, order:params.order, page:params.page, pagesize:params.pagesize, metafilter:params.mf %}
        {% assign data = "" %}
        {% for c in entityview.columns %}
            {% if columns contains c.logical_name %}
                {% assign data = data | append: c.logical_name %}
                <div> {{data}} </div>
            {% endif %}
        {% endfor %}
    {% endentityview %}
{% endentitylist %}

<script>
    function downloadAssets(data){
        console.log(data);
    }
</script>

4

2 回答 2

0

我不知道 Liquid,但可能这段代码可以帮助你。我确实在我的一个项目中检索了列元数据。困难之一是找到包含翻译的对象:

_self._getColumnLocalization = function (entityType, columnName) {
                var result = null;
                var req = new XMLHttpRequest();
                req.open("GET", '../../../api/data/v8.2/EntityDefinitions(LogicalName=%27' + entityType + '%27)?$select=Attributes&$expand=Attributes($select=DisplayName;$filter=LogicalName%20eq%20%27' + columnName + '%27)', false);
                req.setRequestHeader("Accept", "application/json");
                req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
                req.setRequestHeader("OData-MaxVersion", "4.0");
                req.setRequestHeader("OData-Version", "4.0");
                req.setRequestHeader("Prefer", "odata.include-annotations=\"OData.Community.Display.V1.FormattedValue\"");
                req.onreadystatechange = function () {
                    if (this.readyState == 4) {
                        req.onreadystatechange = null;
                        if (this.status == 200) {
                            if (this.response) {
                                result = JSON.parse(this.response);
                            }
                        }
                        //else if (this.status == 204) {
                        //    // Everything then well
                        //}
                        else {
                            alert('Error: ConsumeAPI');
                        }
                    }
                };
                req.send();
                if (result.Attributes.length == 0) {
                    return null;
                }
                else {
                    return result.Attributes[0].DisplayName.UserLocalizedLabel.Label;
                }
            };
于 2019-11-15T15:41:14.037 回答
0

试试这个:

...href="#" title="Download" id="downloadButton">Download ...

<script type="text/javascript">
$("a#downloadButton").click(function() {
downloadAssets({{data}});
});

function downloadAssets(myData){
//here the logic to download the data; 
}
</script>
于 2019-11-25T15:32:48.173 回答