0

我有一个链接到远程源的枚举字段,当您在字段中键入远程源提供匹配项时,它会像您期望的那样弹出。它工作得很好。但我需要该字段位于表单中。问题是,当它处于表单中时,它不再起作用。我剥离了代码并将其列在下面。希望下面的代码就足够了,但是您可以单击提供的链接来尝试它并在接下来的几周左右查看源代码。

谁能解释如何使它在表单中工作?

此代码有效(在此处尝试):

<html>
<head>
    <title>Remote Source Enum</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
    <script type="text/javascript" src="http://rawgit.com/vitmalina/w2ui/master/dist/w2ui.min.js"></script>
    <link rel="stylesheet" type="text/css" href="http://rawgit.com/vitmalina/w2ui/master/dist/w2ui.min.css" />
</head>
<body>
<div class="w2ui-field"><label>Name Picker:</label><div> <input id="tcidPicker"></div></div>
<script>
$('#tcidPicker').w2field('enum', {
    url: '/v1/transactantstd/ISO',
    renderItem: function (item) {return item.FirstName + ' ' + item.LastName; },
    renderDrop: function (item) {return item.FirstName + ' ' + item.LastName; },
    compare: function (item, search) {
        // ... lines removed for brevity ...
    }
});
</script>
</body>
</html>

此代码不起作用(在此处尝试):

<html>
<head>
    <title>Remote Source Enum in a Form</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
    <script type="text/javascript" src="http://rawgit.com/vitmalina/w2ui/master/dist/w2ui.min.js"></script>
    <link rel="stylesheet" type="text/css" href="http://rawgit.com/vitmalina/w2ui/master/dist/w2ui.min.css" />
</head>
<body>
<div id="form">
    <div class="w2ui-field">
    <label>Name Picker:</label><input id="tcidPicker" name="tcidPicker">
    </div>
</div>
<script type="text/javascript">
$(function () {
    $('#form').w2form({ 
        name  : 'form',
        fields: [
            { field: 'tcidPicker', 
                type: 'enum', 
                url: '/v1/transactantstd/ISO',
                renderItem: function (item) {return item.FirstName + ' ' + item.LastName; },
                renderDrop: function (item) {return item.FirstName + ' ' + item.LastName; },
                compare: function (item, search) {
                    // ... lines removed for brevity
                },
            },
        ],
    });
});
</script>
</body>
</html>
4

1 回答 1

0

您需要将选项包装在options属性中。

请参阅:http ://w2ui.com/web/docs/1.5/w2form.fields

在你的情况下:

    fields: [
        { field: 'tcidPicker', 
            type: 'enum', 
            options: {
                url: '/v1/transactantstd/ISO',
                renderItem: function (item) {return item.FirstName + ' ' + item.LastName; },
                renderDrop: function (item) {return item.FirstName + ' ' + item.LastName; },
                compare: function (item, search) {
                    // ... lines removed for brevity
                },
            },
        },
    ],
于 2017-03-01T10:45:04.353 回答