使用 Knockout.js 在文本区域中添加数据绑定和静态文本

Adding data-bind and static text in textarea using Knockout.js

本文关键字:文本 添加 数据绑定 静态 区域 Knockout js 使用      更新时间:2023-09-26

我想将静态文本和属性添加到文本区域。例如,我想显示" [开发x]在[开始日期]开始工作",其中Development_Name()和Start_Date()分别是存储名称和日期的属性

这就是文本区域的外观,Development_Name() 属性工作正常

<text area rows="6" class="textarea-box" id="txtComments" data-bind="Development_Name()"

如何将静态文本附加到此内容。这样做(如下)显然是不正确的

textarea rows="6" class="textarea-box" id="txtComments" data-bind="Development_Name()'+Started work on+'Start_Date()"></textarea>

任何建议

在 .js 文件中创建一个方法并向其添加数据绑定值可以解决此问题。

这是视图

<textarea rows="6" class="textarea-box" id="txtComments" data-bind="value: EmailBodyText"></textarea>

这就是视图模型的外观

 SendEmail: function () {
        if (FlagResult() == "EI") {
           // $("#rowWrapParticipation").addClass('alert alert-danger');
            EmailBodyText("There was an attempt by your company to enter " + SponsorName() + "-" + $("#ddlDevelopment option:selected").text() + ". Unfortunately, at this time, you do not meet the controlled insurance program requirements to come onto the project site. Please contact Rebecca Osborne at Consolidated Risk Solutions via 678.893.7483 or rebecca.osborne@c-r-solutions.com to address this issue");
        }