如何在ng repeat(angularJS)内创建Select
我的选择选项有问题,当我做第一个选择时,选择的内容变为空 以下是我的app.html和app.js app.html nodeCss.css如何在ng repeat(angularJS)内创建Select,angularjs,Angularjs,我的选择选项有问题,当我做第一个选择时,选择的内容变为空 以下是我的app.html和app.js app.html nodeCss.css 当我添加子级或同级并且我想选择一个选项时,第一次添加选项可用,但当我第二次添加选项时,选项消失了,这是因为您使用选项(即数组)作为ng模型。对于ng模型,您需要一个不同的变量。因此,当您选择时,您的选择将成为唯一可用的选项,因为它是您的新数组,它是由于ng模型而绑定的 这样做: <select ng-model="modelChoices" ng-
当我添加子级或同级并且我想选择一个选项时,第一次添加选项可用,但当我第二次添加选项时,选项消失了,这是因为您使用选项(即数组)作为ng模型。对于ng模型,您需要一个不同的变量。因此,当您选择时,您的选择将成为唯一可用的选项,因为它是您的新数组,它是由于ng模型而绑定的 这样做:
<select ng-model="modelChoices" ng-options="choice as choice.name for choice in choices"></select>{{modelChoices}}
angular.module("Webapp", ["ngSanitize","directive.contextMenu"])
.controller("treeCtrl", ['$scope', function($scope) {
$scope.choices=[
{id:'1',name:'Division'},
{id:'2',name:'Grain de contenu'},
$scope.delete = function(data) {
data.nodes = [];
};
$scope.addSibling = function(data) {
var post = data.parent.nodes.length + 1;
var newName = data.parent.name + '-' + post;
data.parent.nodes.push({name: newName,nodes: [], parent: data.parent});
};
$scope.addChild = function(data) {
var post = data.nodes.length + 1;
var newName = data.name + '-' + post;
data.nodes.push({name: newName,nodes: [], parent: data});
};
$scope.tree = [{name: "Node", nodes: []}];
}]);
ul {
list-style: none;
border-left: 1px dashed #ddd;
}
li {
margin-left: 20px;
}
button {
background: #63AE12;
color: #FFF;
border: 0;
font-size: 0.8em;
margin: 9px;
}
button.addchild {
background: #3094E7;
}
button.delete {
background: orange;
}
<select ng-model="modelChoices" ng-options="choice as choice.name for choice in choices"></select>{{modelChoices}}