如何从JS局部视图.cshtml文件中的复选框中获取主要模态的动态更改Knockout js?

问题描述

我有一个主视图_New.cshtml,从这个视图中我叫局部视图_Contact.cshtml。

_New.cshtml

这里有一个“打印”复选框,它根据参数dataModel.Files([@ i] .IsPrint

@for (var i = 0; i < Model.Files.Count; i++)
{
  <div>
    <strong>Print</strong>
    <input type="checkBox" data-bind="checked: dataModel.Files() 
    [@i].IsPrint,value: dataModel.Files()[@i].IsPrint()" 
    id="IsPrint,click: getPrint.bind($data,@i)" name="Documents[@i].IsPrint" />
  </div>
  <div class="contactsgrid" data-bind="foreach: contacts">
    @{
             Html.RenderPartial("_Contact",Model);
     }
  </div>

}

_Contact.cshtml

在这里也有一个复选框,其中我已将传递的dataModel绑定为“ IsEmail”。

@{var v = Model.Files[Model.Index].Contacts[Model.Index].IsEmail ? "true" : "false";}
<input type="checkBox" data-bind="checked:@v,click: $parent.getEmail.bind($data,@Model.Index)" />

new.js

两个视图都有通用的js文件

this.getEmail = function (index) {  
     if (dataModel.Files()[index].IsPrint() == true) {
             dataModel.Files()[index].IsPrint(false);      
         }
         else {
            dataModel.Files()[index].IsPrint(true);       
           }
           return true;
};
this.getPrint = function (index) {  
     if (dataModel.Files()[index].IsPrint() == true) {
             dataModel.Files()[index].Contacts()[index].IsEmail(false);   
         }
         else {
            dataModel.Files()[index].Contacts()[index].IsEmail(true);    
           }
   return true;
};

因此,在contact.cshtml中的复选框上单击时,我正在为相应的索引更改模型中IsPrint的布尔值。最终,它在主视图中被选中或取消选中。但是,当我尝试单击“从主视图打印”,然后在js中更新IsEmail值时,模型值更改未反映在部分视图中(选中:始终保持初始值)吗?如何在局部视图中获取模型的范围并动态地更改参数?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)