2

angular-schema-form 是否有显示预选值的方法?当 select 上的 titleMap 将设置一个整数时,将显示预选值。但如果它会设置一个对象,我发现无法显示正确的名称。

有什么可以将对象绑定到的,比如 ng-options ,您可以在其中设置属性以将它们与“track by”子句进行比较?

ng-options="option as option.name for option in array track by option.id"

在我的示例代码中,cats1 将设置一个对象,cats2 将设置一个整数。

HTML:

  <body>
    <div ng-controller="MainCtrl">
      <div class="login-container">
        <form name="myForm" 
              sf-schema="schema" 
              sf-form="form" 
              sf-model="model">
          
        </form>
      </div>
    </div>
  </body>

控制器:

app.controller('MainCtrl', ['$scope', function ($scope) {

  $scope.form = [
    {
      key: 'cats1',
      type: 'select',
      titleMap: [
        {value: {id: 0, name: "Leopard"}, name: "Leopard"},
        {value: {id: 1, name: "Tiger"}, name: "Tiger"}
      ]
    },
    {
      key: 'cats2',
      type: 'select',
      titleMap: [
        {value: 0, name: "Leopard"},
        {value: 1, name: "Tiger"}
      ]
    }
  ];

  $scope.schema = {
    "type": "object",
    "properties": {
      "cats1": {
        "title": "Cats",
        "type": "object"
      },
      "cats2": {
        "title": "Cats",
        "type": "number"
      }
    }
  };

  $scope.model = {cats1: {id: 1, name: "Tiger"}, cats2: 1};
}]);

这是一个 plunkr: https ://plnkr.co/edit/0hK5Hrc9GXklfRwa6fjE?p=preview

4

0 回答 0