使用 Knockout.js 在 textarea 中添加数据绑定和静态文本
Adding data-bind and static text in textarea using Knockout.js
我想将静态文本和 属性 添加到文本区域。例如我想显示“[Development x] started work on [Start Date]”,其中 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");
}
我想将静态文本和 属性 添加到文本区域。例如我想显示“[Development x] started work on [Start Date]”,其中 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");
}