简体   繁体   中英

dijit/form/FilteringSelect and dojox.data.XmlStore

I have a problem with the filteringSelect and a store created with dojox.data.XmlStore. After the element is loaded, it shows the ID instead of the title (from displayedValue).

After the page is loaded - The unexpected result

How can i fix this? Is there a workaround? (Maybe i only have two left hands...)

The HTML-File:

<!DOCTYPE html>
<html >
    <head>

        <link rel="stylesheet" href="resources/js/dojo/dijit/themes/claro/claro.css">
        <script>dojoConfig = {parseOnLoad: true}</script>
        <script src='resources/js/dojo/dojo/dojo.js'></script>
        <script>
            dojo.require("dojox.data.XmlStore");
            var store = new dojox.data.XmlStore({url: "test.xml", rootItem: "states", keyAttribute:"id", label:"name"});
            require([
                "dojo/store/Memory", "dijit/form/FilteringSelect", "dojo/domReady!"
            ], function(Memory, FilteringSelect){

            var filteringSelect = new FilteringSelect({
                    id: "stateSelect",
                    name: "state",
                    displayedValue : "test",
                    store: store,
                    searchAttr: "name",
                    labelAttr:'name',
                    labelType: "text"
                }, "stateSelect").startup();
            });

        </script>
    </head>
    <body class="claro">

        <input id="stateSelect">

    </body>
</html>

The "text.xml":

<?xml version="1.0" encoding="UTF-8"?>
<states>
    <state>
        <id>3</id>
        <name>important</name>
    </state>
    <state>
        <id>4</id>
        <name>also important</name>
    </state>
    <state>
        <id>5</id>
        <name>test</name>
    </state>
    <state>
        <id>8</id>
        <name>scumm</name>
    </state>
</states>

it looks like you rootItem is the cause of the problem. You're specifying rootItem as the root document node, but rootItem is for specifying your core items (items to show)

If rootItem is not provided, then the XmlStore assumes the tags under the root element of the document are the root items.

so in your case rootItem should be "state" insteadOf "states"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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