吴生成重复内NG-模型 [英] Generate ng-model inside ng-repeat

查看:183
本文介绍了吴生成重复内NG-模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在读几个主题,但不可能找到解决这一个,我被困在。

I have been reading a few topics but couldnt find a solution to this one I am stuck on.

我想补充的 NG-模型 NG-重复是这样的:

I am trying to add ng-model inside ng-repeat something like this:

<span ng-repeat="list in lists">
         <input type="checkbox" ng-model="formData.checkboxes.{{ list.value }}"> {{ list.number }} {{ list.description }} <br/>
</span>

和列表值是这样的:

$scope.lists = [

    {

        value:'value1',
        number: '1',
        description:'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ',    
    },

    {
        value:'value2',
        number: '2',
        description:'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ', 
        },

        {
        value:'value3',
        number: '3',
        description:'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ',            },
    ];

在NG-repeat循环,我想它来建立一个NG-模型,如: formData.checkboxes.value1 formData.checkboxes.value2,formData.checkboxes.value3 等等。

Inside the ng-repeat loop, I want it to build a ng-model like: formData.checkboxes.value1 formData.checkboxes.value2, formData.checkboxes.value3 etc..

这可能吗?当我尝试上述方法没有显示出来。我在做什么错在这里?

Is this possible? When I try the above method nothing shows up. What am I doing wrong here?

推荐答案

您控制器内部首先你应该确定 formData.checkboxes 模式是这样的:

First you should define formData.checkboxes model inside your controller like this:

$scope.formData = {
    checkboxes: {}
};

...和你可以填充它这样的:

... and the you can populate it like that:

<span ng-repeat="list in lists">
    <input type="checkbox" ng-model="formData.checkboxes[list.value]"/> 
             {{ list.value }} {{ list.number }} {{ list.description }} <br/>
</span>

请看看这个的jsfiddle 获得工作的例子。

Please take a look at this JSFiddle for working example.

这篇关于吴生成重复内NG-模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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