javascript - ng-model 不更新对象

标签 javascript angularjs

我有一个表单,旨在让用户编辑一些信息

我的问题是 <input class="form-control" type="text" ng-repeat="info in item.Question" ng-model="info"/> 。当我单击“保存”按钮时,日志(下面复制的示例)告诉我它没有更新模型。谁能明白为什么吗?

我读到了其他一些问题,说 ng-model 需要一个 object.property 值,但我不知道如何在这里应用它

<div class="panel panel-primary" ng-show="item.edit">

<div class="panel-heading">
    <h3 class="panel-title">
        <form class="form-group form-inline">
            <input class="form-control" type="text" ng-model="item.Name" />
            <span class="badge pull-right">&#8356;<input class="form-control" type="number" step="any" ng-model="item.Price" /></span>
        </form>
    </h3>
</div>
<div class="panel-body">
    <input class="form-control" type="text" ng-model="item.Desc" />
    <hr>
    <div class="col-md-11">
        <input class="form-control" type="text" ng-repeat="info in item.Question" ng-model="info"/>
    </div>
    <div class="col-md-1">
        <a href="" ng-click="cat.newQuestion(item)" class="btn btn-success"><span class="glyphicon glyphicon-plus"></span></a>
    </div>
</div>
<div class="panel-footer">
    <div class="btn-group">
        <a href="" ng-click="cat.change(item)" class="btn btn-success">Save</a>
        <a href="" ng-click="item.edit = false" class="btn btn-primary">Cancel</a>
        <a href="" ng-click="cat.deleteItem(item)" class="btn btn-danger">Delete</a>
        </div>
    </div>
</div>

来自 change() 的日志示例功能:

app.js:39 Object {ID: "10", Name: "New User", Price: 0, Desc: "Create a new user for the Quarriers network", CatID: "3"…}$$hashKey: "object:50"CatID: "3"Desc: "Create a new user for the Quarriers network"ID: "10"Name: "New User"Price: 0Question: "username,"edit: true
app.js:40 stringing
app.js:46 Object {ID: "10", Name: "New User", Price: 0, Desc: "Create a new user for the Quarriers network", CatID: "3"…}$$hashKey: "object:50"CatID: "3"Desc: "Create a new user for the Quarriers network"ID: "10"Name: "New User"Price: 0Question: "username,"edit: true__proto__: Object

最佳答案

如果您不想将 Question 更改为具有属性的对象,您可以使用以下内容:

<input ng-repeat="info in item.Question track by $index" ng-model="item.Question[$index]"/>

关于javascript - ng-model 不更新对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37587567/

相关文章:

angularjs - Angular ui grid双击事件设置

javascript - 包括 Google Analytics WordPress

javascript - js 正则表达式量词和全局标志输出空字符串作为匹配数组中的最后一个元素

javascript - AngularJS 混合来自不同模块的同名 Controller

javascript - Chart.js 2.x 动画 onComplete 没有响应

angularjs - pdfjs : How to create more than one canvas to show all the pages?

javascript - Javascript 中值列表的动态验证

javascript - Javascript 的稀疏数组是如何构造的?每个索引中放置了什么?

javascript - 浏览器实际上如何将 DOM 数据存储在最低级别?它存储为表还是树?

javascript - AngularJS: Angular 过滤器:如何按 2 列进行分组?