简体   繁体   English

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

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

I want to add both static text and a property to a text area. 我想将静态文本和属性添加到文本区域。 For example I want to display " [Development x] started work on [Start Date]" where Development_Name() and Start_Date() are properties that store the name and date respectively 例如,我要显示“ [开发x]在[开始日期]上开始工作”,其中Development_Name()和Start_Date()是分别存储名称和日期的属性

This is what the text area looks like and the Development_Name() property works fine 这是文本区域的外观,Development_Name()属性可以正常工作

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

How do I append static text to this. 我该如何添加静态文本。 Doing it this way (below) is obviously incorrect 这样做(下)显然是不正确的

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

Any suggestions 有什么建议么

Creating a method in the .js file and adding a data-bind value to it solves the problem. 在.js文件中创建方法并向其中添加数据绑定值即可解决该问题。

Here's the view 这是视图

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

This is what the view model will look like 这就是视图模型的样子

 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");
        }

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

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