为了账号安全,请及时绑定邮箱和手机立即绑定

AngularJS:将模态返回的数据绑定到从中单击的行

AngularJS:将模态返回的数据绑定到从中单击的行

摇曳的蔷薇 2021-05-06 14:20:59
在这里使用AngularJS。我正在使用具有下拉菜单的UI。根据用户选择的内容,我向用户显示2个选项卡。每个选项卡数据都是从服务返回的,该服务仅返回数据数组(字符串)。针对返回的每个字符串值,我显示一个针对它的按钮。当您单击按钮时,它将打开一个模式弹出窗口,用户可以在其中选择一些数据。当他们关闭模态时,我将数据返回给控制器。将数据绑定到选项卡,打开模式并从模式返回数据的正常流程都可以正常工作。我无法理解或设计的是如何将返回的数据绑定到单击它的按钮或行上例如如下:Tab1String1 - Button1String2 - Button2String3 - Button3如果我通过单击button1打开模式,则如何找出button1被按下并绑定回从其模式返回的数据。一些相关的代码如下:<div id="params" ng-if="type.selected">  <tabset class="tabbable-line">    <tab heading="Sets" ng-if="sets" active="tab.set">            <div class="form-group m-grid-col-md-8 param" style="margin-top:5px"             ng-repeat="set in sets" >              <label class="control-label col-md-3 param-label">{{set}}              </label>                                <button ng-click="openModal()" class="btn btn-info btn-sm">                Select              </button>         </div>    </tab>    <tab heading="Tables" ng-if="tables" active="tab.table">               <div class="form-group m-grid-col-md-8 param"             ng-repeat="table in tables">            <label class="control-label col-md-3 param-label">{{table}}            </label>                           <button ng-click="openModal()" class="btn btn-info btn-sm">                Select            </button>            </div>        </tab>    </tabset></div> 控制器:  $scope.onChangeType = function (selectedValue) {                  $scope.getData(selectedValue);  };  $scope.getData = function (selectedValue) {      //Commenting out the service part for now and hardcoding array      // service.getData(selectedValue).then(function (res) {           $scope.sets = ['Set1', 'Set2', 'Set3'];              $scope.tables = ['Table1', 'Table2'];      // });  };  $scope.openModal = function () {       myFactory.defineModal().then(function (response) {            //how to bind data from response        });   };我为此示例创建了一个plnkr:http ://plnkr.co/edit/vqtQsJP1dqGnRA6s?preview
查看完整描述

2 回答

?
幕布斯6054654

TA贡献1876条经验 获得超7个赞

将table对象作为参数传递给openModal函数:


<button ng-click="openModal(table)">Select</button>

在openModal函数中使用它:


$scope.openModal = function (table) {

     myFactory.defineModal().then(function (result) {

         table.utype = result.utype;

         table.minvalue = result.minvalue;

     });

};

确保使用结果关闭模式:


$scope.ok = function () {

    var result = { 

      utype: $scope.utype,

      minvalue: $scope.minvalue,

    };

    $modalInstance.close(result); 

};

请记住,模态被认为是破坏性的,并且被用户鄙视。


一般来说,干扰和分心会负面影响人类的表现,这是认知心理学中的一项常见发现。许多研究表明,分心极大地增加了在各种任务上的任务时间。


有关更多信息,请参见


虽然我没有收到任何错误,但是我没有得到返回的文本。

请确保为以下物品提供物品ng-repeat

 $scope.getData = function (selectedValue) {

      //Commenting out the service part for now and hardcoding array

      // service.getData(selectedValue).then(function (res) {

           ̶$̶s̶c̶o̶p̶e̶.̶t̶a̶b̶l̶e̶s̶ ̶=̶ ̶[̶'̶T̶a̶b̶l̶e̶1̶'̶,̶'̶T̶a̶b̶l̶e̶2̶'̶]̶;̶

           $scope.tables = [

             {name:'Table1',},

             {name:'Table2',},

          ];

      // });

  };


查看完整回答
反对 回复 2021-05-20
?
米琪卡哇伊

TA贡献1998条经验 获得超6个赞

尝试将传递table给openModal模板中的


<button ng-click="openModal(table)"

现在,您可以将其用作openModal函数中的参考


$scope.openModal = function (table) {

  // table === the clicked table

}


查看完整回答
反对 回复 2021-05-20
  • 2 回答
  • 0 关注
  • 250 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号