添加一个编辑器选项卡SurveyJS - 不能够绑定到模型

问题描述 投票:0回答:2

我与添加应用程序特定分页SurveyJS,它本身不支持试验。我到目前为止已经做的是增加一个收件人型号,例如:

import * as ko from "knockout";

export class RecipientsModel {
    public firstName: string = 'Chris';
    constructor() {}
    public show() {}
}

和模板(recipients.html):

<script type="text/html" id="recipients">
  <div class="form-item form-type-textarea form-item-bulk-accounts">
    <label class="control-label" for="edit-bulk-accounts">Email addresses <span class="form-required" title="This field is required.">*</span></label>
    <div class="form-textarea-wrapper resizable textarea-processed resizable-textarea"><textarea class="form-control form-textarea required" id="edit-bulk-accounts" name="bulk_accounts" cols="60" rows="5"></textarea><div class="grippie"></div></div>
    <div class="description">Email addresses for participants you would like to register.  Enter one per line.</div>
  </div>
  <span data-bind="text: firstName">Test</span>
</script>

我修改editor.ts让我的标签显示,并填充内容:

this.recipient = new RecipientsModel();
...
...
...
public showManageRecipients() {
    if (!this.canSwitchViewType(null)) return;
    this.recipient.firstName = 'Chris';
    // this.showSurveyRecipients();
    this.koViewType("recipients")
}

因此,与我有什么到目前为止,我有一个显示静态内容我想要一个标签。下一步是找出当前正在破碎的结合:

knockout-min.js:72 Uncaught ReferenceError: Unable to process binding "template: function(){return { name:'recipients'} }"
Message: Unable to process binding "text: function(){return firstName }"
Message: firstName is not defined
at text (eval at parseBindingsString (knockout-min.js:68), <anonymous>:3:57)
at update (knockout-min.js:98)
at function.a.B.i (knockout-min.js:72)
at Function.Pc (knockout-min.js:51)
at Function.Qc (knockout-min.js:51)
at Function.aa (knockout-min.js:50)
at Object.a.m.a.B (knockout-min.js:49)
at knockout-min.js:72
at Object.q (knockout-min.js:11)
at m (knockout-min.js:71)

由于这是我第一次与任KnockoutJS或SurveyJS搞乱,我挣扎,使这个简单的物业工作的结合。我目前正在经历KnockoutJS文件,但同样,我不知道这是调试的正确路径。

编辑更多的调试之后,我已经更新了我的模型设定firstNameko.observablefirstName = ko.observable("");。而且,SurveyJs代码库中我将它用this.recipient.firstName('Chris');。我现在可以使用:<span data-bind="text: recipient.firstName">Test</span>这是好的 - 但我想我应该以某种方式结合在不要求使用recipient.firstName的方式模型,我可以只使用firstName。也许我错了。编辑完

所以,我在这一点上的主要问题:如何使this.recipient.firstName工作的模板中的绑定?

knockout.js knockout-3.0 surveyjs
2个回答
0
投票

你可以改变使用with结合的结合方面:

<script type="text/html" id="recipients">
  <div class="form-item form-type-textarea form-item-bulk-accounts">
    <label class="control-label" for="edit-bulk-accounts">Email addresses <span class="form-required" title="This field is required.">*</span></label>
    <div class="form-textarea-wrapper resizable textarea-processed resizable-textarea"><textarea class="form-control form-textarea required" id="edit-bulk-accounts" name="bulk_accounts" cols="60" rows="5"></textarea><div class="grippie"></div></div>
    <div class="description">Email addresses for participants you would like to register.  Enter one per line.</div>
  </div>
  <!-- ko with: recipient -->
  <span data-bind="text: firstName">Test</span>
  <!-- /ko -->
</script>

1
投票

更新:

由于1.0.69你可以通过下面的代码添加自定义选项卡到SurveyJS编辑器(生成器):

  editor.tabs.push({
    name: "custom",
    title: "Custom Tab",
    template: "custom-template-id",
    data: {
      data: "Custom data"
    },
    action: () => {
      if (!editor.canSwitchViewType(null)) return;
      editor.koViewType("custom");
    }
  });

你也需要添加相应的模板:

  <script type="text/html" id="custom-template-id">
    <div data-bind="text: data">
    </div>
  </script>
© www.soinside.com 2019 - 2024. All rights reserved.