简体   繁体   English

我的输入字段的值正确,但未呈现

[英]I have input fields where their value is correct, but it is not being rendered

I made a plunker with the exact thing i am trying to accomplish, just where it works: http://embed.plnkr.co/Qjh4FLZY428Vvjc7koXf/ . 在工作的地方,我用了我想完成的确切工作: http ://embed.plnkr.co/Qjh4FLZY428Vvjc7koXf/。 Same version of riotjs and everything :/ 相同版本的riotjs和所有东西:/

I am taking over a code base using Riot.js, and there is this auto-complete tag looking like this: 我正在使用Riot.js接管代码库,并且有一个如下所示的自动完成标记:

    <autocomplete>
<div class="input-group {open : showResults}">
    <div class="input-group-addon">
        <i class="fa {opts.setup.iconclass}"></i>
    </div>
    <input type="text" name={opts.setup.name} class="form-control" onblur={opts.onblur} placeholder={opts.setup.placeholder} value={self.setup.valueSelected} onkeyup={keyup}/>
    <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
        <li each={res in results}><a href="#" onclick={valueSelected}>{res.title}</a></li>
    </ul>
</div>

<script>
var self = this;

self.timer = null;
self.showResults = false;
self.results = [];

var value = "";
self.keyup = function(e) {
    value = e.target.value;
    clearTimeout(self.timer)
    self.timer = setTimeout(self.performSearch, opts.setup.timeout);
}

self.performSearch = function() {
    if(value == "") {
        self.showResults = false;
        self.update();
    } else {
        $.ajax({
            url: opts.setup.url + encodeURIComponent(value),
            success: function(resp) {
                var data = resp;
                if(typeof(data) == "string") {
                    data = JSON.parse(resp);
                }

                if(!Array.isArray(data)) {
                    data = data[Object.keys(data)[0]];

                }

                self.results = data.map(function(obj) {
                    var str = "";

                    self.opts.setup.title.split(',').forEach(function(key) {
                        str += obj[key] + " ";
                    });
                    return {title: str, original: obj};
                });

                if(self.results.length > 0) {
                    self.showResults = true;
                    self.update();
                }
            },
            error: function(err) {
                console.log(err);
            }
        });
    }
}


self.valueSelected = function(e) {
    e.preventDefault();
    self.showResults = false;
    self.update();
    opts.setup.callback(e.item.res.original, opts.fieldName);
}
</script>
</autocomplete>

From the outside we simply render it with: 从外部,我们只需使用以下命令进行渲染:

self.addressac = {
    name: "form.Address",
    iconclass: "fa-map",
    placeholder: "Find addresse",
    selectedValue: "",
    timeout: 1000,
    url: "https://someendpoint?q=",
    title: "tekst",
    callback: function(selectedValue) {
        self.addressac.selectedValue = selectedValue.tekst;

        self.order.Address = selectedValue.adresse.vejnavn;
        self.order.Number = selectedValue.adresse.husnr;
        self.order.AddressUUID = selectedValue.adresse.id;
        if(selectedValue.adresse.etage != null) {
            self.order.Floor = selectedValue.adresse.etage;
            if(selectedValue.adresse['dør'] != null) {
            self.order.Floor = self.order.Floor + " " + selectedValue.adresse['dør'];
            }
        }
        self.order.Zip = selectedValue.adresse.postnr;
        RiotControl.trigger('reports-on-address', self.order.AddressUUID);
        RiotControl.trigger('order-associationcvr-from-address', selectedValue.adresse);
        self.update();
    }
};

and the component are being rendered as: 并且该组件被呈现为:

                    <autocomplete setup={addressac}> </autocomplete>

What is really weird is that the self.update() works, because it sets the autocomplete input fields value attribute to the correct new value selected from the dropdown, but it doesn't render the value attribut in the html, it just keeps rendering its initial value. 真正奇怪的是self.update()起作用了,因为它将自动完成输入字段的value属性设置为从下拉列表中选择的正确新值,但是它没有在html中呈现值属性,而是一直呈现它的初始值。 Have anyone tried similar with Riot.js? 有人尝试过Riot.js吗?

解决方案是将riot.js版本2.3。*更新到最新版本,即3.6。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Polymer JS 输入值可以设置但不会在 UI 中呈现 - Polymer JS input value can be set however not being rendered in the UI 一旦所有字段都输入正确,如何使用 javascript 启用“创建帐户”按钮? - How can I use javascript to enable a “create account” button once all fields have correct input? 如果输入字段的值相同,则求和它们的值 - sum input fields value if they have the same value 检查所有子输入字段是否都具有值 - Check if all children input fields have a value jQuery 计算有值的输入字段的数量 - jQuery count number of input fields that have a value 动态添加 <input> 没有被渲染 - Dynamically added <input> not being rendered 如何获取我单击的特定表单的输入字段的值,所有 forms 及其输入具有相同的 class 但值不同 - How to get the value of input fields of a particular form on which i clicked ,all the forms and their input have the same class but different value 未呈现新属性值 - New property value not being rendered 我试图访问 DOM 中无线电输入的名称属性,但显然所有名称字段的值都为 false? - I tried to access the name property of a radio input in the DOM, but apparently all the name fields have a value of false? 这是从获取请求中在React中显示数据的正确方法,如果不是,我如何更改呈现给组件的JSX? - Is this the correct way to show data in React from a fetch request, if not how do I change JSX being rendered to a component?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM