Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用AngularJs从表生成JSON以保存表格数据?_Javascript_Html_Json_Angularjs - Fatal编程技术网

Javascript 如何使用AngularJs从表生成JSON以保存表格数据?

Javascript 如何使用AngularJs从表生成JSON以保存表格数据?,javascript,html,json,angularjs,Javascript,Html,Json,Angularjs,我在AngularJS的帮助下创建了一个HTML <form name="target" ng-submit="createAllKeywordsJSON(codeMasterList)"><!-- createAllKeywordsJSON() --> <input type="submit" value="Save" class="myButton" name="submit" style="margin: 0px;float:right;">

我在AngularJS的帮助下创建了一个HTML

<form name="target" ng-submit="createAllKeywordsJSON(codeMasterList)"><!-- createAllKeywordsJSON() -->
    <input type="submit" value="Save" class="myButton" name="submit" style="margin: 0px;float:right;">

    <div class="category-placer2" style="width:100%">
      <div class="category-header-keywords">
        <div class="icon-add"><a href="#"><img src="images/icon-add.png" alt="Add" border="0" title="Add phone Number" /></a></div>
        <div class="category-header-text" ><span ng-bind="dispName"></span></div>
      </div>
      <div class="category-base">
        <div class="keywordplacer">

            <table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" class="keywordsList">
                <tr>                
                    <th width="60%" colspan="2">Code Master Name</th>
                    <th width="30%" colspan="2">Status</th>
                </tr>
                <tr ng-repeat="type in codeMasterList">
                    <td width="1%" class="">
                        <input type="hidden" name="codeMasterId" value="{{type.codeMasterId}}" />
                    </td>
                    <td width="60%" class="">
                        <input type="text" name="keywordName" value="{{type.name}}" alt="Name of Keyword" size="60" >
                    </td>
                    <td width="30%" class="">
                        <input type="radio" value="1" name="{{type.codeMasterId}}" alt="Name of Keyword" ng-checked="{{(type.activeInd == 1) && ('true') || ('false')}}" />Active
                        <input type="radio" value="0" name="{{type.codeMasterId}}" alt="Name of Keyword" ng-checked="{{(type.activeInd == 0) && ('true') || ('false')}}" style="margin-left:50px;" />Inactive
                    </td>
                </tr>
            </table>

        </div>
        <center>
            <hr style=" background-color: #ABBFC6; height: 2px; width: 90%;">
            <input type="submit" value="Save" class="myButton" style="margin: 0px;"/>
        </center>
        <!-- <div class="table-index">P - Primary</div> -->
      </div>
    </div>
</form>

$scope.codemastlist
将是列表的
JSON
数据

您可以使用
ng model
而不是
value
来更新表单字段的值。这也会将输入值绑定回列表中的项。因此,您只需保存
$scope.codeMasterList

HTML示例



谢谢你的回答,但我想将最新的{{mylist}}传递给控制器,这样我就可以将其传递给服务并通过hibernate保存,所以在提交表单后,你能帮我将其传递给控制器吗?你可以帮助我,你不需要传递一个引用来获取列表到控制器。如果你想去除angular
ng repeat
$$hashkey,然后执行
angular.copy($scope.myList)
它在JSFIDLE中工作正常,但是当我尝试将其转换为真实代码时,它会向我显示错误:“angular.foreach不是一个函数”,你能帮帮我吗?我不知道你为什么要换我的小提琴,你不需要
angular.forEach()
我又更新了小提琴请看,你在
ng checked
$scope中添加了很多额外的代码。好的
你不需要的函数。
keywordModule.controller('keywordTypeController',['$scope', '$http', 'keywordService',
    function($scope, $http, keywordService) {
        $scope.createAllKeywordsJSON = function() {
            //alert($scope.codeMasterList.codeMasterId);
            var tempItemList = [];
            angular.foreach($scope.codeMasterList,function(item,index){
                tempItemList.push(item);
            });
            alert(tempItemList);
            /*keywordService.createAllKeywordsJSON().query(codeMasterList,
                    //Success Handler handler
                    function(data) {

                    },
                    //Failure handler
                    function(error) {

                    }
            );*/
            //alert(codeMasterList);
        };
    }
]);
<input type="text" ng-model="type.name" alt="Name of Keyword" size="60" >