pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <tfoot id='E4kIX'></tfoot>
    <legend id='E4kIX'><style id='E4kIX'><dir id='E4kIX'><q id='E4kIX'></q></dir></style></legend>

      <small id='E4kIX'></small><noframes id='E4kIX'>

        <bdo id='E4kIX'></bdo><ul id='E4kIX'></ul>
        <i id='E4kIX'><tr id='E4kIX'><dt id='E4kIX'><q id='E4kIX'><span id='E4kIX'><b id='E4kIX'><form id='E4kIX'><ins id='E4kIX'></ins><ul id='E4kIX'></ul><sub id='E4kIX'></sub></form><legend id='E4kIX'></legend><bdo id='E4kIX'><pre id='E4kIX'><center id='E4kIX'></center></pre></bdo></b><th id='E4kIX'></th></span></q></dt></tr></i><div class="xo73rzr" id='E4kIX'><tfoot id='E4kIX'></tfoot><dl id='E4kIX'><fieldset id='E4kIX'></fieldset></dl></div>

        jQuery:與在不適當(dāng)?shù)臅r(shí)間執(zhí)行的 removeData() 沖突

        jQuery: Conflict with removeData() executing at inadequate times(jQuery:與在不適當(dāng)?shù)臅r(shí)間執(zhí)行的 removeData() 沖突)
            <bdo id='XYYcx'></bdo><ul id='XYYcx'></ul>

            <small id='XYYcx'></small><noframes id='XYYcx'>

              <legend id='XYYcx'><style id='XYYcx'><dir id='XYYcx'><q id='XYYcx'></q></dir></style></legend>
              <i id='XYYcx'><tr id='XYYcx'><dt id='XYYcx'><q id='XYYcx'><span id='XYYcx'><b id='XYYcx'><form id='XYYcx'><ins id='XYYcx'></ins><ul id='XYYcx'></ul><sub id='XYYcx'></sub></form><legend id='XYYcx'></legend><bdo id='XYYcx'><pre id='XYYcx'><center id='XYYcx'></center></pre></bdo></b><th id='XYYcx'></th></span></q></dt></tr></i><div class="eewnbzm" id='XYYcx'><tfoot id='XYYcx'></tfoot><dl id='XYYcx'><fieldset id='XYYcx'></fieldset></dl></div>

                  <tbody id='XYYcx'></tbody>
                • <tfoot id='XYYcx'></tfoot>
                  本文介紹了jQuery:與在不適當(dāng)?shù)臅r(shí)間執(zhí)行的 removeData() 沖突的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我有一個(gè)模式窗口,用于更新或添加新對象Store.

                  I have a modal window used to update or add a new object Store.

                  此模式被遠(yuǎn)程調(diào)用,其信息從 ASP.NET 中構(gòu)造的 GET 方法加載.

                  This modal is called remotely which information is loaded from a GET method constructed in ASP.NET.

                  調(diào)用模態(tài)的按鈕:

                  <div class="btn-group" id="modalbutton">
                      <a id="createEditStoreModal" data-toggle="modal" asp-action="Create" 
                           data-target="#modal-action-store" class="btn btn-primary">
                              <i class="glyphicon glyphicon-plus"></i>  NEW STORE
                          </a>
                  </div>
                  

                  模態(tài)的HTML:

                  @model Application.Models.ApplicationviewModels.StoreIndexData
                  @using Application.Models
                  
                  <form asp-action="Create" role="form">    
                          @await Html.PartialAsync("_ModalHeader", new ModalHeader
                      { Heading = String.Format("Actualización de Modelo: Tiendas") })
                  
                          <div asp-validation-summary="ModelOnly" class="text-danger"></div>
                          <div class="modal-body form-horizontal">
                              <div class="form-group">
                                  <label asp-for="DepartmentID" class="col-md-2 control-label"></label>
                                  <div class="col-md-10">
                                      <select asp-for="DepartmentID" class="form-control"
                                              asp-items="@(new SelectList(@ViewBag.ListofDepartment,"DepartmentID","DepartmentName"))"></select>
                                  </div>
                              </div>
                              <div class="form-group">
                                  <label class="col-md-2 control-label">Distrito</label>
                                  <div class="col-md-10">
                                      <select class="form-control" id="DistrictID" name="DistrictID" asp-for="DistrictID"
                                              asp-items="@(new SelectList(@ViewBag.ListofDistrict,"DistrictID","DistrictName"))"></select>
                                  </div>
                              </div>
                              {... more elements}
                         </div>
                  </form>
                  

                  GET方法:

                      public IActionResult Create(int? id)
                      {
                          List<Department> DepartmentList = new List<Department>();
                          DepartmentList = (from department in _context.Departments
                                            select department).ToList();
                          DepartmentList.Insert(0, new Department { DepartmentID = 0, DepartmentName = "-- Seleccione Departamento --" });
                          ViewBag.ListofDepartment = DepartmentList;
                  
                          StoreIndexData edit = new StoreIndexData();
                          List<District> ListofDistrict = new List<District>();
                          ListofDistrict.Insert(0, new District { DistrictID = 0, DistrictName = "-- PRUEBA --" });
                          ViewBag.ListofDistrict = ListofDistrict;
                  
                          return PartialView("~/Views/Shared/Stores/_Create.cshtml");
                      }
                  

                  問題:

                  我有以下 jQuery,一旦模式打開,它就會為 DistrictID 分配一個(gè)值:

                  I have the following jQuery which asigns a value to DistrictID once the modal opens:

                  <script type="text/javascript">
                  
                      var wasclicked = 0;
                      var $this = this;
                  
                      $(document).ready(function () {
                  
                          document.getElementById("modalbutton").onclick = function () {
                              //is AddNew Store button is hitted, this var = 1
                              wasclicked = 1;
                          };
                  
                          $('#modal-action-store').on('hidden.bs.modal', function () {
                              //global.wasclicked = 0;
                              wasclicked = 0;
                              $(this).removeData('bs.modal');
                          });
                  
                          $('#modal-action-store').on('shown.bs.modal', function (e) {
                              console.log($('#DistrictID').length);
                              //if wasclicked equals 1 that means we are in the AddNew Store scenario.
                              if (wasclicked == 1) {
                                  //a default value is sent to District dropdownlist
                                  var items = "<option value='0'>-- Seleccione Distrito --</option>";
                                  $('#DistrictID').html(items);
                              };
                          });
                      });
                  </script>
                  

                  現(xiàn)在的問題是,在這行 jQuery 執(zhí)行之后,分配給 DistrictID 的值被 :

                  The problem right now is that after this line jQuery is executed, the value that was assigned to DistrictID gets overwritten by :

                    ViewBag.ListofDistrict = ListofDistrict; //"-- PRUEBA --"
                  

                  而這一行丟失了:

                  var items = "<option value='0'>-- Seleccione Distrito --</option>";
                  

                  我懷疑來自 Controller 的信息會覆蓋模態(tài)中的 jQuery 的任何結(jié)果.

                  What I suspect is that the information coming from the Controller overwrites any result from jQuery over the in the modal.

                  調(diào)試后我發(fā)現(xiàn)了三個(gè)不同的時(shí)刻:

                  After debugging I have identified three diferent moments:

                  時(shí)刻 1:我們第一次打開模式

                  • 模態(tài)尚未打開,jQuery 正在執(zhí)行
                  • 因此它無法識別 DistrictID
                  • GET 操作的結(jié)果填充模態(tài)的輸入.

                  時(shí)刻 2 - 第 1 部分:我們第二次打開模式

                  • 這次模態(tài)框在 jQuery 執(zhí)行之前打開
                  • 在我們從 jQuery 分配值之前,DistrictID 具有來自 GET 方法的值
                  • This time the modal opens before the jQuery is executed
                  • The DistrictID has the value from the GET Method before we assign the value from jQuery

                  時(shí)刻 2 - 第 2 部分:分配來自 jQuery 的值時(shí)

                  • 來自 jQuery 的值被分配給 DistrictID
                  • 此值將被 GET 操作的結(jié)果覆蓋

                  問題:

                  誰能解釋或幫助我了解可能導(dǎo)致這種情況的原因?我還能做些什么來找出這背后的原因?

                  Can anyone explain or help me understand what might be causing this? What else can I do to identify the reason behind this?

                  推薦答案

                  嘗試將html到districtID的分配從你的主視圖移動到modal的document.ready彈出視圖.

                  Trying moving the assigning of html to districtID from your main view to the document.ready of modal popUp view.

                      @model Application.Models.ApplicationviewModels.StoreIndexData
                      @using Application.Models
                  
                      <form asp-action="Create" role="form">    
                              @await Html.PartialAsync("_ModalHeader", new ModalHeader
                          { Heading = String.Format("Actualización de Modelo: Tiendas") })
                  
                              <div asp-validation-summary="ModelOnly" class="text-danger"></div>
                              <div class="modal-body form-horizontal">
                                  <div class="form-group">
                                      <label asp-for="DepartmentID" class="col-md-2 control-label"></label>
                                      <div class="col-md-10">
                                          <select asp-for="DepartmentID" class="form-control"
                                                  asp-items="@(new SelectList(@ViewBag.ListofDepartment,"DepartmentID","DepartmentName"))"></select>
                                      </div>
                                  </div>
                                  <div class="form-group">
                                      <label class="col-md-2 control-label">Distrito</label>
                                      <div class="col-md-10">
                                          <select class="form-control" id="DistrictID" name="DistrictID" asp-for="DistrictID"
                                                  asp-items="@(new SelectList(@ViewBag.ListofDistrict,"DistrictID","DistrictName"))"></select>
                                      </div>
                                  </div>
                                  {... more elements}
                             </div>
                      </form>
                  
                  <script type="text/javascript">
                  
                      $(document).ready(function () {
                              //if wasclicked equals 1 that means we are in the AddNew Store scenario.
                              if (wasclicked == 1) {
                                  //a default value is sent to District dropdownlist
                                  var items = "<option value='0'>-- Seleccione Distrito --</option>";
                                  $('#DistrictID').html(items);
                              }
                      });
                  
                  </script>
                  

                  PS:也可以使用默認(rèn)選項(xiàng).參考下面的代碼.

                  PS: Default option can be also be used. refer the below code.

                  <div class="form-group">
                   <label class="col-md-2 control-label">Distrito</label>
                    <div class="col-md-10">
                     <select class="form-control" id="DistrictID" name="DistrictID" asp-for="DistrictID" asp-items="@(new SelectList(@ViewBag.ListofDistrict,"DistrictID","DistrictName"))">
                       <option value='0'>-- Seleccione Distrito --</option>
                    </select>
                   </div>
                  </div>
                  

                  這篇關(guān)于jQuery:與在不適當(dāng)?shù)臅r(shí)間執(zhí)行的 removeData() 沖突的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  Check if a polygon point is inside another in leaflet(檢查一個(gè)多邊形點(diǎn)是否在傳單中的另一個(gè)內(nèi)部)
                  Changing leaflet markercluster icon color, inheriting the rest of the default CSS properties(更改傳單標(biāo)記群集圖標(biāo)顏色,繼承其余默認(rèn) CSS 屬性)
                  Trigger click on leaflet marker(觸發(fā)點(diǎn)擊傳單標(biāo)記)
                  How can I change the default loading tile color in LeafletJS?(如何更改 LeafletJS 中的默認(rèn)加載磁貼顏色?)
                  Adding Leaflet layer control to sidebar(將 Leaflet 圖層控件添加到側(cè)邊欄)
                  Leaflet - get latitude and longitude of a marker inside a pop-up(Leaflet - 在彈出窗口中獲取標(biāo)記的緯度和經(jīng)度)

                • <legend id='3NeF0'><style id='3NeF0'><dir id='3NeF0'><q id='3NeF0'></q></dir></style></legend>
                  <i id='3NeF0'><tr id='3NeF0'><dt id='3NeF0'><q id='3NeF0'><span id='3NeF0'><b id='3NeF0'><form id='3NeF0'><ins id='3NeF0'></ins><ul id='3NeF0'></ul><sub id='3NeF0'></sub></form><legend id='3NeF0'></legend><bdo id='3NeF0'><pre id='3NeF0'><center id='3NeF0'></center></pre></bdo></b><th id='3NeF0'></th></span></q></dt></tr></i><div class="w77ehfd" id='3NeF0'><tfoot id='3NeF0'></tfoot><dl id='3NeF0'><fieldset id='3NeF0'></fieldset></dl></div>

                  <small id='3NeF0'></small><noframes id='3NeF0'>

                      • <bdo id='3NeF0'></bdo><ul id='3NeF0'></ul>

                              <tbody id='3NeF0'></tbody>
                            <tfoot id='3NeF0'></tfoot>
                            主站蜘蛛池模板: 动物麻醉机-数显脑立体定位仪-北京易则佳科技有限公司 | 北京成考网-北京成人高考网 | 合肥钣金加工-安徽激光切割加工-机箱机柜加工厂家-合肥通快 | 中矗模型-深圳中矗模型设计有限公司 | 扫地车厂家-山西洗地机-太原电动扫地车「大同朔州吕梁晋中忻州长治晋城洗地机」山西锦力环保科技有限公司 | 微学堂-电动能源汽车评测_电动车性能分享网 | 微妙网,专业的动画师、特效师、CG模型设计师网站! - wmiao.com 超声波电磁流量计-液位计-孔板流量计-料位计-江苏信仪自动化仪表有限公司 | 济南货架定做_仓储货架生产厂_重型货架厂_仓库货架批发_济南启力仓储设备有限公司 | 伟秀电气有限公司-10kv高低压开关柜-高低压配电柜-中置柜-充气柜-欧式箱变-高压真空断路器厂家 | 钢格板_钢格栅_格栅板_钢格栅板 - 安平县鑫拓钢格栅板厂家 | 地图标注|微信高德百度地图标注|地图标记-做地图[ZuoMap.com] | 网络推广公司_网络营销方案策划_企业网络推广外包平台-上海澜推网络 | 示波器高压差分探头-国产电流探头厂家-南京桑润斯电子科技有限公司 | 橡胶接头|可曲挠橡胶接头|橡胶软接头安装使用教程-上海松夏官方网站 | 滑板场地施工_极限运动场地设计_滑板公园建造_盐城天人极限运动场地建设有限公司 | 锂辉石检测仪器,水泥成分快速分析仪-湘潭宇科分析仪器有限公司 | 本安接线盒-本安电路用接线盒-本安分线盒-矿用电话接线盒-JHH生产厂家-宁波龙亿电子科技有限公司 | 【北京写字楼出租_写字楼租赁_办公室出租网/出售】-远行地产官网 | 济南品牌包装设计公司_济南VI标志设计公司_山东锐尚文化传播 | 消防泵-XBD单级卧式/立式消防泵-上海塑泉泵阀(集团)有限公司 | 硫化罐-电加热蒸汽硫化罐生产厂家-山东鑫泰鑫智能装备有限公司 | 会议会展活动拍摄_年会庆典演出跟拍_摄影摄像直播-艾木传媒 | 网优资讯-为循环资源、大宗商品、工业服务提供资讯与行情分析的数据服务平台 | 预制舱-电力集装箱预制舱-模块化预制舱生产厂家-腾达电器设备 | 蜂窝块状沸石分子筛-吸附脱硫分子筛-萍乡市捷龙环保科技有限公司 | ?水马注水围挡_塑料注水围挡_防撞桶-常州瑞轩水马注水围挡有限公司 | 手持式浮游菌采样器-全排二级生物安全柜-浙江孚夏医疗科技有限公司 | 隧道窑炉,隧道窑炉厂家-山东艾瑶国际贸易| 金库门,金库房,金库门厂家,金库门价格-河北特旺柜业有限公司 | 高防护蠕动泵-多通道灌装系统-高防护蠕动泵-www.bjhuiyufluid.com慧宇伟业(北京)流体设备有限公司 | 湖南档案密集架,智能,物证,移动,价格-湖南档案密集架厂家 | 电动高尔夫球车|电动观光车|电动巡逻车|电动越野车厂家-绿友机械集团股份有限公司 | 节流截止放空阀-不锈钢阀门-气动|电动截止阀-鸿华阀门有限公司 | 一点车讯-汽车网站,每天一点最新车讯!| 石家庄律师_石家庄刑事辩护律师_石家庄取保候审-河北万垚律师事务所 | ◆大型吹塑加工|吹塑加工|吹塑代加工|吹塑加工厂|吹塑设备|滚塑加工|滚塑代加工-莱力奇塑业有限公司 | 槽钢冲孔机,槽钢三面冲,带钢冲孔机-山东兴田阳光智能装备股份有限公司 | 爱科技iMobile-专业的科技资讯信息分享网站 | 刑事律师_深圳著名刑事辩护律师_王平聚【清华博士|刑法教授】 | 河南橡胶接头厂家,河南波纹补偿器厂家,河南可曲挠橡胶软连接,河南套筒补偿器厂家-河南正大阀门 | 济南冷库安装-山东冷库设计|建造|冷库维修-山东齐雪制冷设备有限公司 |