javascript - 在 ng-repeat 中绑定(bind) ngmodel 的正确方法

标签 javascript angularjs

我有这个

"List": {
"lorem": 127,
"ipson": 5.5,
"dolor": 29,
"sit": 19}

然后我使用以下 ng-repeat 代码创建一个包含输入字段的表格

<table>
        <tr ng-repeat="(item, weight in settings.list">
            <th>
                <input ng-model="item"></input>
            </th>
            <th>
                <input ng-model="weight"></input>
            </th>
        </tr>
</table>

现在我显然希望 ng-model 更新父范围,但我不知道该怎么做

最佳答案

您可能想要一个这样的列表:

list : [
  {
   name : "lorem",
   weight : 127
  },
  {
   name : "haha",
   weight : 12
  }
];

然后:

<table>
        <tr ng-repeat="item in settings.list">
            <th>
                <input ng-model="item.name"></input>
            </th>
            <th>
                <input ng-model="item.weight"></input>
            </th>
        </tr>
</table>

关于javascript - 在 ng-repeat 中绑定(bind) ngmodel 的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23865022/

相关文章:

javascript - 在循环中组合多个语句

javascript - RESTful Web 服务中的身份验证

javascript - 是否可以在加载任何图像之前运行 JavaScript?

javascript - Angular ,将范围传递给函数(将范围作为变量传递?)

javascript - 需要帮助将 Chart.js 图表添加到模态窗口(我正在使用 AngularJS)

javascript - 在 AngularJS 中单击行时如何在模式中显示特定行的详细信息

angularjs - 无法从后端下载带有输出流数据的 Excel 电子表格

javascript - D3.js 如何使用折线图在我的图例中添加工具提示

javascript - 如何将页面加载后计算出的数据发送到 MongoDB?

html - 在 Angular 模板中对齐 2 个 <ul> block