将Knockout绑定到JXQUERY GRID

时间:2014-10-16 19:06:55

标签: javascript knockout.js

我想将knockout observable数组集成并绑定到我的jxquery网格。此外,当我单击我的搜索按钮时,它会刷新我的网格。我下面的代码没有在加载时或搜索后将我的observable数组绑定到我的网格

JS

  var initialData = [
    { username: "test", transdate: "test2" },
    ];


    var self = this;

    self.reportTitle = ko.observable();

    self.selectedUser = ko.observable();

    self.startDate = ko.observable();

    self.endDate = ko.observable();

    self.users = ko.observableArray();

    self.results = ko.observableArray(initialData);


    function initialize() {

        dataModel.getUsers()
          .success(function (data) {
              $.each(data, function () {
                  var obj = { id: this._id, username: this.username }
                  self.users.push(obj);
              })
          }).fail(function () {
              self.errors.push("An unknown error occurred.");
          });
    };

    initialize();

    self.errors = ko.observableArray();

    self.search = function () {
        dataModel.getCompoundLog(self.selectedUser(), self.startDate(), self.endDate()).success(function (data) {
            $.each(data, function () {
                var obj = { username: this.user.username, transdate: this.transdate }
                self.results.push(obj);
            }) 
        }).fail(function () {
            self.errors.push("An unknown error occurred.");
        });
        $("#jqxgrid").jqxGrid('updatebounddata');
    }



}


app.addViewModel({
    name: "Report",
    bindingMemberName: "report",
    factory: ReportViewModel
});

查看

<div data-bind="jqxGrid: {source: results, autoheight: true,
                columns: [
                    { text: 'username', dataField: 'username', width: 200 },
                    { text: 'transdate', dataField: 'transdate', width: 200, cellsalign: 'right' },
                ]}" id="jqxgrid"></div>

0 个答案:

没有答案