拥有多种动态选择框angularjs [英] Having multiple dynamic select boxes angularjs

查看:111
本文介绍了拥有多种动态选择框angularjs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立使用 Papaparse 一个CSV重要的联系方式。该网站上的角运行。

I built a csv contact importer using Papaparse. The site runs on angular.

这是我的方式:

<div ng-show="import_file_selected">
    <form ng-submit="processImport()" name="importForm">
        <div class="row">
            <div class="col-md-12">
                <table class="table table-hover">
                    <tr>
                        <th ng-show="has_header" class="col-md-4">Header</th>
                        <th class="col-md-4">Attribute</th>
                        <th class="col-md-4">Value Sample</th>
                    </tr>
                    <tr ng-repeat="row in rows">
                        <td ng-show="has_header">{{row.header}}</td>
                        <td>
                            <select class="form-control" name="{{row.header}}">
                                <option value="">Ignore</option>
                                <option ng-repeat="attribute in attributes" value="{{attribute.key}}">{{attribute.val}}</option>
                                <option value="add">Add Attribute</option>
                            </select>
                        </td>
                        <td>{{row.values}}</td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="row">
            <div class="col-md-6 form-group col-md-offset-3">
                <button class="btn btn-primary btn-block" type="submit">Save Import</button>
            </div>
        </div>
    </form>
</div>

该HTML给出了这样的结果:

The HTML gives this result:

在这里输入的形象描述

到目前为止,这一切功能和显示正常。不过,我不知道如何捕捉数据在我的 processImport()功能。

So far, this all functions and displays correctly. However, I have no idea how to capture the data in my processImport() function.

我想用绑定的,但是从选择框,因为用户可以添加/删除属性,我不能pre-构建选择框。并且由于每个CSV可以有不同数量的列,我需要与每列有重复

I thought of using binding, but since a user can add/remove attributes from the select box, I can't pre-build the select box. And since each csv can have a different number of columns, I need to repeat with each column there is.

我如何能捕捉到这里提交的数据有什么建议?请让我知道我是否应该添加任何东西。

Any suggestions on how I can capture the data submitted here? Please let me know if I should add anything else.

推荐答案

因此​​,对于那些像这样苦苦挣扎,这真的不是那么复杂。是的,我知道我在说,现在,但当你看到的解决方案,它是pretty简单。

So for those struggling with something like this, it's really not that complex. Yes, I know I'm saying that now, but when you see the solution, it's pretty simple.

所以我有这样的对象:

var $scope.rows = {
    'header': "Account Code",
    'header_safe': "Account Code",
    'options': ["Ignore", "Cellphone Number", "First Name", "Full Name", "Last Name", "Title","Add Attribute"],
    'values: "WELG01, ABDO01, ABOO01, ABOO2, ABOO02, ABOU01, ABRA03, ABRA01, ABRA02, ACKE04"
},{
    'header': "Customer Name"
    'header_safe': "Customer Name"
    'options': ["Ignore", "Cellphone Number", "First Name", "Full Name", "Last Name", "Title","Add Attribute"],
    'values': ", Abdool, Aboo, Aboobaker, Aboobaker, Abouchabki, Abraham Thato, Abrahams, Abrams, Ackerman Rulaine"
}

其中,如果你看到上面你会承认什么会显示在我的问题图像中的图像。为了得到这些工作的下拉菜单,这是我的HTML是什么样子:

Which, if you see the image above you'd recognise as what is displayed in the image in my question. To get those dropdowns working, this is what my HTML looks like:

<table class="table table-hover">
    <tr>
        <th ng-show="has_header" class="col-md-4">Header</th>
        <th class="col-md-4">Attribute</th>
        <th class="col-md-4">Value Sample</th>
    </tr>
    <tr ng-repeat="row in rows">
        <td ng-show="has_header">{{row.header}}</td>
        <td>
            <select class="form-control" ng-model="select[row.header_safe]" ng-options="option for option in row.options"></select>
        </td>
        <td>{{row.values}}</td>
    </tr>
</table>

然后,在我的表单提交,我只是有一个 processImport()功能。这个函数是这样的:

Then, on my form submit, I just have a processImport() function. That function looks like this:

$scope.processImport = function() {
    console.log($scope.select);
}

和映入我的所有数据。

一个更清洁的例子可 rel=\"nofollow\">。由于href=\"http://stackoverflow.com/a/12556590/1238303\">原作者,因为他明确地回答我的问题的

A cleaner example is available here. Thanks to the original author, as he definitively answered my question.

这篇关于拥有多种动态选择框angularjs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆