简体   繁体   English

数据绑定未在视图页面中显示数据

[英]data-bind not displaying data in view page

This is how I have my page set up, but no data is being displayed, and I'm not sure why: 这是我设置页面的方式,但是没有显示任何数据,我不确定为什么:

JavaScript/knockout: JavaScript /淘汰赛:

 var getList = function () {
            Ajax.Get({
                Url: ...,
                DataToSubmit: {id: properties.Id },
                DataType: "json",
                OnSuccess: function (roleData, status, jqXHR) {
                    bindModel(roleData);

                }
            });
        };


    // Binds the main ViewModel
        var bindModel = function (data) {
            var _self = viewModel;

            ko.applyBindings(viewModel, $('#ListView')[0]);
        };

    var viewModel = {
            ListRoleTypes: ko.observableArray([]),
            .....
        };

 var roleViewModel = function (data) {
        var _self = this;
        _self.ContentRole = ko.observable(data.ContentRole);
        _self.RoleName = ko.observable(data.RoleName);
        _self.RoleRank = ko.observable(data.RoleRank);
        _self.UserCount = ko.observable(data.UserCount);
    };

This is my View page: 这是我的查看页面:

<div data-bind="foreach: ListRoleTypes">
            <span data-bind="text: RoleName"></span>
        </div>

Any thoughts on where I am going wrong? 对我要去哪里错有任何想法吗?

you are calling bindmodel and passing in the roledata, but then in bindmodel, you dont do anything with it. 您正在调用bindmodel并传入角色数据,但是随后在bindmodel中,您对其不执行任何操作。

Ajax.Get({
            Url: ...,
            DataToSubmit: {id: properties.Id },
            DataType: "json",
            OnSuccess: function (roleData, status, jqXHR) {
                bindModel(roleData);

            }
        });
    };


// Binds the main ViewModel
    var bindModel = function (data) {
        // need to do something with viewmodel to handle the passed in data
        viewmodel.initialize(data);

        ko.applyBindings(viewModel, $('#ListView')[0]);
    };

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

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