angular 表格动态行

        前端页面需要做成按钮动态控制行数的效果以及对输入内容做一些检验。

        效果图:

        

       html

        

                       <td>
                            <label class="col-sm-2 control-label">关键词配置</label>
                            <table class="table table-striped table-bordered responsive no-m">
                                <tr>
                                    <td width="30%">关键词</td>
                                    <td width="60%">内  容</td>
                                    <td width="10%"><a style="color:red;" ng-click="addKeywordConfig()">增加</a></td>
                                </tr>
                                <tr data-ng-repeat="k in keywords">
                                    <td>
                                        <input required type="input" value="k.keyword"  data-ng-model="$parent.keywords[$index].keyword"
                                         maxlength="32" pattern="^((?!{param.*}).)+$"/>
                                    </td>
                                    <td>
                                        <input required type="input" value="k.text" data-ng-model="$parent.keywords[$index].text"
                                         maxlength="480"/>
                                    </td>
                                    <td>
                                        <a style="color:red;" ng-click="delKeywordConfig($index)">移除</a>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="3">
                                        <p>
                                            <span class="help-block text-error" ng-show="showKeywordsContentNotice"
                                                  data-ng-bind="keywordNoticeContent"></span>
                                        </p>
                                        <p>
                                            <span class="help-block text-error" ng-show="showKeywordNotice"
                                                  data-ng-bind="keywordNoticeKeyword"></span>
                                        </p>
                                    </td>
                                </tr>

                            </table>
                        </td>

        js

              

	$scope.keywords = [];

	function Keyword() {
		return{
		keyword:"",text:""
		}
	}


 
       $scope.addKeywordConfig = function () {
            if ($scope.keywords.length > 3) {
                Tips.info("最多可配置四个参数!");
                return;
            }
            var keyword = new Keyword();
            $scope.keywords.push(keyword);
        };

        $scope.delKeywordConfig = function (idx) {
            $scope.keywords.splice(idx, 1);
        };

        /**
         * 关键词对应内容检测敏感词
         */
        $scope.$watch("keywords",function(newValue, oldValue){
            if(newValue.length < 1) {
                $scope.showKeywordsContentNotice = false;
                $scope.showKeywordNotice = false;
                return;
            }
            var text = "";
            var keyword = "";
            for(var i = 0; i< newValue.length;i++) {
                var newText = newValue[i].text;
                var newKeyword = newValue[i].keyword;
                text += newText+",";
                keyword += newKeyword+",";
            }
            $scope.validateKeywordContent(text);//后台校验逻辑
            $scope.validateKeyword(keyword);//后台校验逻辑

        },true);


  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值