【问题标题】:getJSON with a domino view - not returning any data带有多米诺骨牌视图的 getJSON - 不返回任何数据
【发布时间】:2016-03-09 06:35:03
【问题描述】:

我正在开发一个基于 @TheoHeselmans 关于使用 Knockoutjs 启用 Web 启用 Domino 应用程序的演示文稿的应用程序。

我有点卡住了。

我正在尝试使用以下代码在网页上显示 Domino 视图

    self.mainclient.subscribe(function(newValue) {
        $.getJSON('../api/data/collections/name/json', function(data) {
        var mappedClients = $.map(data, function(item) { return new ClientRow(item); });
        self.renewals(mappedClients);
        });
    }
);

function ClientRow(data) {
    this.Status = ko.observable(data.Status);
}

它不返回任何数据 - 或显示错误,但我在 Domino 控制台上看到 servlet 已启动。

我将 observable 元素设置如下:

self.renewals = ko.observableArray([]);
self.allclients = [{clientName: "ACME COMPANY"},{clientName: "GG Inc"}];
self.mainclient = ko.observable('');

通过从下拉列表中选择主客户端来设置它:

<select class="form-control" id="MainClient" data-bind="options: $root.allclients, value: mainclient, optionsText: 'clientName'">
</select>

最后,模板变量设置为:

 <!-- Knockout JavaScript (+ mapping plug-in and bootbox lib)
================================================== -->
<script src="[DB]js/knockout-3.2.0.js"></script>
<script src="[DB]js/knockout.mapping-latest.js"></script>
<script src="[DB]js/bootbox.min.js"></script>

<!-- Templates -->

<script type="text/html" id="renewal-template">
          <tr>
            <td data-bind="text: Status" /></td>
 </tr>
</script>

<script src="[DB]pages/ko_renewals.js"></script>

以及将其称为:

<table class="table table-striped table-condensed"><tr class="warning"><th>Status</th></tr>
<tbody data-bind="template: { name: renewal-template', foreach: renewals }">
</tbody>
</table>
<pre data-bind="text: ko.toJSON($data, null, 2)"></pre>

&lt;pre&gt; 元素不返回任何内容 - 即使它位于 &lt;table&gt;&lt;tbody&gt; 内。如果放置在 &lt;select&gt; 元素内,它确实会返回值。

我要显示的视图是

json view

对我错过的任何帮助将不胜感激。

谢谢

格雷姆

【问题讨论】:

  • 您是否尝试在浏览器中打开该链接? http[s]:////api/data/collections/name/json 您是否为服务器和数据库激活了“Domino 数据服务”?

标签: json knockout.js lotus-domino


【解决方案1】:

已排序。

function Renewal(data) {
    this.Country = ko.observable(data.Country);
    this.Status = ko.observable(data.Status);
    this.updatelink = data['@link'] || '';
}

function AppViewModel() {
   var self = this;

   //create empty observable Array
   self.renewals = ko.observableArray([]);
   self.allclients = ko.observableArray([]);
   self.mainclient = ko.observable('');


   //Get list of Countries
   $.getJSON('../api/data/collections/name/(lookupclient)', function(data) {
        self.allclients(data[0].Client);
        self.mainclient(self.allclients[0]);
        }
   );

   //trigger an AJAX request to get tastings when the main country selection changes
   self.mainclient.subscribe(function(newValue) {
        $.getJSON('../api/data/collections/name/json?count=5&keys=' + newValue, function(data) {
        var mappedRenewals = $.map(data, function(item) { return new Renewal(item); });
        self.renewals(mappedRenewals);
        });
    });


}

ko.applyBindings(new AppViewModel());

var vm = ko.dataFor(document.body); //for debugging

【讨论】:

    猜你喜欢
    • 2022-08-14
    • 2021-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-25
    • 1970-01-01
    相关资源
    最近更新 更多