dojo autopopulate示例不起作用

时间:2011-05-21 19:19:43

标签: combobox dojo

我从dojo网站获得了这个例子。但这不适合我。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<head>
    <style type="text/css">
        body, html { font-family:helvetica,arial,sans-serif; font-size:90%; }
    </style>
    <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojo/dojo.xd.js"
    djConfig="parseOnLoad: true">
    </script>
    <script type="text/javascript">
        dojo.require("dijit.form.FilteringSelect");
        dojo.require("dojo.data.ItemFileReadStore");
    </script>
    <script type="text/javascript">
        dojo.addOnLoad(function() {
            var stateStore = new dojo.data.ItemFileReadStore({
                url: "../../_static/js//dijit/tests/_data/states.json"
            });
            var filteringSelect = new dijit.form.FilteringSelect({
                id: "stateSelect",
                name: "state",
                value: "KY",
                store: stateStore,
                searchAttr: "name"
            },
            "stateSelect");
        });
    </script>
    <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dijit/themes/claro/claro.css"
    />
</head>

<body class=" claro ">
    <input id="stateSelect">
    <p>
        <button onClick="alert(dijit.byId('stateSelect').get('value'))">
            Get value
        </button>
        <button onClick="alert(dijit.byId('stateSelect').get('displayedValue'))">
            Get displayed value
        </button>
    </p>
    <!-- NOTE: the following script tag is not intended for usage in real
    world!! it is part of the CodeGlass and you should just remove it when
    you use the code -->
    <script type="text/javascript">
        dojo.addOnLoad(function() {
            if (document.pub) {
                document.pub();
            }
        });
    </script>
</body>

1 个答案:

答案 0 :(得分:3)

首先,您应该删除此代码:

 <!-- NOTE: the following script tag is not intended for usage in real
    world!! it is part of the CodeGlass and you should just remove it when
    you use the code -->
    <script type="text/javascript">
        dojo.addOnLoad(function() {
            if (document.pub) {
                document.pub();
            }
        });
    </script>

第二个问题是填充ItemFileReadStore。您的网站上确实有此文件"../../_static/js//dijit/tests/_data/states.json"吗?如果不是,则应创建它(或修复文件路径)或使用其他方法填充ItemFileReadStore。