根据knockout.js值加载不同的模态

时间:2017-06-09 20:34:28

标签: html knockout.js bootstrap-modal

enter image description here

所以我有一张人员信息表,我使用了类似下面的代码(在这种情况下是人们的位置):

  <!-- ko foreach: filteredApplications -->
     <div class="col-md-6">

        <span>Location:</span>

        <span data-bind="text: application.candidateLocation"></span>

     </div>

显示所有人的位置信息。

当我点击“预览应用程序”链接时,它应该给我一个类似于附加图像的模态并显示相应人物的信息。

我试图删除模态的foreach淘汰赛,但是它给了我一个错误,说它无法找到application.candidateLocation变量。

我如何处理此问题?

请帮忙!

编辑(viewmodel):

public partial class Application
    {
     public dynamic JsonForm => new
     {

        CandidateLocation,
        Job = this.Job.JsonForm,
        CandidateStatus = this.CurrentStatuse.CandidateStatus,

    };

    public string CandidateLocation
    {
        get
        {
            switch (ApplicationCandidateType)
            {
                case ApplicationCandidateType.Standard:
                    return InsideApplication.CandidateApplication.Candidate.Location;
                case ApplicationCandidateType.Guest:
                    return null; 
                case ApplicationCandidateType.Manual:
                    return null; 
                default:
                    throw new Exception("Unhandled ApplicationCandidateType");
            }
        }
    }

 function ViewModel() {
        var self = this;

        self.invite = ko.observable(false);

        self.changeStylesInvite = function () {
            self.invite(true);
        }

        self.notifications = ko.observableArray(@Html.Json(Model.Notifications.Select(o => o.JsonForm)) || []);

        self.applications = ko.observableArray(@Html.Json(Model.ApplicationCompatibilities.Select(o => o.JsonForm)) || []);
        self.applicationInvitations = ko.observableArray(@Html.Json(Model.ApplicationInvitations.Select(o => o.JsonForm)) || []);

        self.applicationsFilter = ko.observable("new");
        self.showHiddenApplications = ko.observable(false);

        self.newApplicationsCount = ko.computed(function() {
            return ko.utils.arrayFilter(self.applications(), function(i) {
                return !i.application.isShortlisted && !i.application.isContactInfoSent && (self.showHiddenApplications() || !i.application.isHidden);
            }).length;
        });
        self.shortlistedApplicationsCount = ko.computed(function() {
            return ko.utils.arrayFilter(self.applications(), function(i) {
                return i.application.isShortlisted && (self.showHiddenApplications() || !i.application.isHidden);
            }).length;
        });
        self.connectedApplicationsCount = ko.computed(function() {
            return ko.utils.arrayFilter(self.applications(), function(i) {
                return i.application.isContactInfoSent && (self.showHiddenApplications() || !i.application.isHidden);
            }).length;
        });
        self.allApplicationsCount = ko.computed(function() {
            return ko.utils.arrayFilter(self.applications(), function(i) {
                return (self.showHiddenApplications() || !i.application.isHidden);
            }).length;
        });

0 个答案:

没有答案