javascript - 通过 json 动态地将范围绑定(bind)到 ng-model

标签 javascript angularjs json html

我正在尝试通过 json 自动填充表单,如下所示。 我希望 ng-model 绑定(bind)到 formValue.question001 的范围。怎么可能做到呢?

$scope.formValue = [
    {
        _id: '001',
        text: 'text-001',
    },
    {
        _id: '002',
        text: 'text-002'
    }
]

<form name="form" ng-submit="submitForm(formValue)">
    <div ng-repeat="item in formValue">
        <input type="text" ng-model="formValue.question{{ item._id }}">
    </div>
</form>

最佳答案

1) 您的 formValue 对象中没有属性“question#”。 2)没有办法插入计算表达式,你给ng-model一个表达式,它不是一个简单的字符串,所以你可以做类似ng-model =“questions [item._id]”的事情,其中​​问题是数组位于您的范围内

关于javascript - 通过 json 动态地将范围绑定(bind)到 ng-model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36420382/

相关文章:

javascript - 什么是 Javascript 等同于 iOS 的委托(delegate)函数?

javascript - JSON.parse 在 Node 和 Chrome 中有什么不同?

javascript - 在 AngularJS 中读取 URL 参数 - 一种简单的方法?

javascript - 上传文件nodejs和Angular强大

javascript - 在前端显示 url 响应

javascript - 可靠的服务器以 json 格式获取世界时间

javascript - 未捕获ReferenceError : _ is not defined and Uncaught TypeError: undefined is not a function

javascript - 悬停时的过渡背景图像

javascript - IE 中止 http post 请求并出现错误 0x2ee2

json - Python - UnicodeDecodeError : 'charmap' codec can't decode byte 0x81 in position 44: character maps to <undefined>