Data Binding to a specific item of an array in Angular

前端 未结 3 1974
野的像风
野的像风 2021-02-19 11:41

Given a data structure that contains an array of JavaScript objects, how can I bind a certain entry from that array to an input field using Angular?

The data structure l

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-19 12:24

    I personally would reorganize the array in a way that field property of an entry of the array become the identifier of the object. Mhhh that sentence may sound strange. What I mean is the following:

    $scope.data = {
        name: 'F1',
        fields: {
            F1: {
               value: "1F"
            },
            F2: {
               value: "2F"
            }
        }
    };
    

    If you want to bind a the value dynamically and it's an easy and quick way to achieve it. Here is your fiddle modified so that it words. http://jsfiddle.net/RZFm6/

    I hope that helps

提交回复
热议问题