1

I am using Spring Boot 2.0.6.RELEASE , Thymeleaf 3, Kendo UI jQuery (use this component https://docs.telerik.com/kendo-ui/api/javascript/ui/dropdownlist/configuration/value ),

code html (Thymeleaf template)

<td><label th:for="provinceOrCity">Tỉnh/TP</label></td>
<td>
    <input type="text" th:field="*{provinceOrCity}" class="k-textbox" style="width: 100%;">
    <script>
        $(document).ready(function () {
            var dataProvince = new kendo.data.DataSource({
                transport: {
                    read: {
                        url: "/provinces",
                        dataType: "json"
                    }
                },
                pageSize: 300
            });
            // create DropDownList from input HTML element

            /*<![CDATA[*/
            var intrinsic = [[*{provinceOrCity}]];
            var foo = intrinsic.toString();
            /*]]>*/

            $("#provinceOrCity").kendoDropDownList({
                dataTextField: "text",
                dataValueField: "value",
                dataSource: dataProvince,
                filter: "contains",
                //filter: "startswith",
                suggest: true,
                //index: 0,
                change: onChangeProvince,
                //value: "Hà Nội"
                value: foo
                //value: [[*{provinceOrCity}]]
            });
        });
        // Create DropDownList from select HTML element
        //$("#provinceOrCity").kendoDropDownList();
        //var provinceOrCity_combo = $("#provinceOrCity").data("kendoDropDownList");
        //provinceOrCity_combo.select(0);
        function onChangeProvince() { }
    </script>
</td>

In console screenshot, you see Hà Nội , I want a string variable "Hà Nội" or 'Hà Nội' then it will not cause error.

How to convert [[*{provinceOrCity}]] to JavaScript string variable correctly?

2
  • 1
    Can't you place it in quotes: intrinsic = "[[*{provinceOrCity}]]"? Commented Jul 6, 2019 at 8:45
  • Posted @DoNhuVy. Commented Jul 6, 2019 at 8:52

1 Answer 1

1

Just surround it in quotes - the value is injected before the script runs, so the value will be inserted, then JavaScript will make a string.

var intrinsic = "[[*{provinceOrCity}]]";
Sign up to request clarification or add additional context in comments.

1 Comment

var intrinsic = /*[[${provinceOrCity}]]*/ 'default'; works fine

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.