AngularJS select选项不会将值传递给http post请求

时间:2017-01-22 21:54:35

标签: angularjs select

我有选择框,我使用角度常量传递数据。我有两种不同的类型我写它是因为我试图解决我的问题,但没有成功。问题是我的选择框没有将任何值传递给post请求,我不知道为什么。我也尝试使用ng-option但结果相同。

<!DOCTYPE html>
<html>

  <head>
    <script data-require="d3@4.0.0" data-semver="4.0.0" src="https://d3js.org/d3.v4.min.js"></script>
  </head>

  <body>
    <script>
    var arr = [{
      "name": "John",
      "info": [{
        "age": 31,
        "height": 6,
        "weight": 155,
        "eyes": "green"
      }, {
        "age": 35,
        "height": 6,
        "weight": 165,
        "eyes": "green"
      }]
    }, {
      "name": "Eric",
      "info": [{
        "age": 29,
        "height": 5,
        "weight": 135,
        "eyes": "brown"
      }, {
        "age": 30,
        "height": 5,
        "weight": 155,
        "eyes": "brown"
      }]
    }];

    var vis = d3.select("body").selectAll("div")
      .data(arr)
      .enter()
      .append("div");
      
    vis.append("h1")
      .html((d) => d.name);
      
    var nestedDivs = vis.append("div").append("div");
    
    var innerDiv = nestedDivs.selectAll("div")
      .data((d) => d.info)
      .enter()
      .append("div");
      
    innerDiv.append("h2")
      .html((d) => "Age:" + d.age);
      
    innerDiv.append("div")
      .append("span")
      .html((d) => "Weight: " + d.weight);

  </script>
  </body>

</html>

这里我将这些枚举绑定到我的角度控制器中的范围

(function () {
app.constant("Constants", {
    Status: {
        1 : "New",
        2 : "Active",
        3 : "OnHold",
        4 : "Testing",
        5 : "Finished",
        6 : "Dropped"
    },
    Priority: [
        { id: "1", name: "Low" },
        { id: "2", name: "Medium" },
        { id: "3", name: "High" },
        { id: "4", name: "Urgent" },
    ],
});

这是我的观点,我将来自我的控制器的数据用于我的表单。我根据官方角度文档使用ng-repeat:https://docs.angularjs.org/api/ng/directive/select

    $scope.priority = {
        model: null,
        options: Constants.Priority,
    }
    $scope.status = {
        model: null,
        options: Constants.Status,
    }

我错过了为什么它不能正常工作?

1 个答案:

答案 0 :(得分:0)

您的状态是一个对象,您没有任何id

使用ng-options

<select ng-model="status.model" ng-options="key as value for (key , value) in status.options">
</select>

或ng-repeat如下:

<select ng-model="status.model">
    <option ng-repeat="(key, value) in status.options" value="{{key}}">{{value}}</option>
</select>