简体   繁体   English

SAPUI5 格式化程序 function 在输入控件中无法正常工作

[英]SAPUI5 formatter function not working properly inside Input Control

I need to highlight a few of the table's cell border colors on the basis of a condition and pre-fill it with some negative value.我需要根据一个条件突出显示表格的一些单元格边框 colors 并用一些负值预填充它。 Then I need to SAVE/POST this value to proceed further.然后我需要保存/发布这个值以进一步进行。

View.xml查看.xml

<t:Column width="100px">
    <Label text="ActualQty"/>
    <t:template>
       <Input id="idInput" value="{ parts: [ {path: 'viewData>ACT_QTY'}, {path: 'viewData>MTART'} ], formatter: '._formatter.defaultInput' }">
            <customData>
                <core:CustomData key="colorclass" value="{path: 'viewData>MTART', formatter: '._formatter.formatCell'}" writeToDom="true"/>
            </customData>
       </Input>
    </t:template>
</t:Column>

Formatter.js格式化程序.js

    formatCell: function (iValue) {
        try {
            iValue.toString();
        } catch (err) {
            iValue = "foo";
        }
        return iValue.toString();
    },

    defaultInput: function (iValue, iValue1) {

        if (iValue !== 0 && iValue1 === "HALB") {
            iValue = "-1";
            return iValue;
        } else {
            return iValue;
        }
    }

style.css样式.css

    div[data-colorclass="HALB"] { 
      border: 4px solid #fdf6b1 !important;
    }

Highlighting and the default value is appearing.突出显示并出现默认值。 But inside the controller, The input value is not coming.但是在controller里面,输入值不来。

if I remove parts and pass single input param to formatter function, its working.如果我删除零件并将单个输入参数传递给格式化程序 function,它的工作原理。 But I need both the values to built my logic.但是我需要这两个值来构建我的逻辑。

Update更新

Now I am using Composite Binding to make the binding as Two-way.现在我使用复合绑定将绑定设置为双向。

View.xml查看.xml

<Input id="idInput" value="{ parts: [ {path: 'viewData>ACT_QTY'}, {path: 'viewData>MTART'} ], type: '._Compound', formatter: '._formatter.defaultInput' }">

Compound.js复合.js

 sap.ui.define([ "sap/ui/model/CompositeType", "dismantling/bom/integration/model/type/Compound" ], CompositeType => CompositeType.extend('Compound', { constructor: function () { CompositeType.apply(this, arguments); this.bParseWithValues = true; // make 'parts' available in parseValue }, formatValue: iValue => iValue, parseValue: bValue => bValue, validateValue: vValue => { /*validate...*/ }, }));

In the controller file, I am passing Compound type as "_Compound".在 controller 文件中,我将复合类型传递为“_Compound”。 I am not getting any errors in the console.我在控制台中没有收到任何错误。

Still, I am not able to get the formatter passed value inside the controller.尽管如此,我还是无法在 controller 中获取格式化程序传递的值。

Please guide.请指导。

Your formatter is correct.您的格式化程序是正确的。 Make sure sure that the values are actually accessible under your binding path and that the formatter is accessible to the view.确保在绑定路径下可以实际访问这些值,并且视图可以访问格式化程序。 If both these things are ensured, your function will work just fine.如果这两件事都得到保证,你的 function 就可以正常工作了。

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

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