我是一名自学编程新手,致力于使用 node、angular、bootstrap 和图形数据库 neo4j 开发 Web 应用程序。
我希望在下面的代码中得到一些关于我做错了什么的指示。
破碎的HTML:
<div class='btn-group' ng-controller="typeCtrl" ng-repeat="type in display">
<button class='btn' ng-click='whatsmyname(type)' > {{type}}</button>
<button class='btn dropdown-toggle dropdown'><span class='caret'></span></button>
<ul class= 'dropdown-menu'>
<li><a>Exclue Term</a></li>
<li><a>Exclue and Load</a></li>
<li><a>Include</a></li>
<li><a>Include and Load</a></li>
</ul>
<p>Hello? {{display}}</p>
角度控制器:
function typeCtrl($scope){
var theList = [];
var alltheterms;
var things = [{"name":"Image","tags":["Type","Image","Core"]},{"name":"GIF","tags":["Type","Image"]},{"name":"Infographic","tags":["Type","Image"]},{"name":"Chart","tags":["Type","Image"]},{"name":"Photo","tags":["Type","Image"]},{"name":"Microscope","tags":["Type","Image"]},{"name":"Telescope","tags":["Type","Image"]},{"name":"Text","tags":["Type","Text","Core"]},{"name":"Article","tags":["Type","Text"]},{"name":"Short Story","tags":["Type","Text"]},{"name":"Quote","tags":["Type","Text"]},{"name":"Podcast","tags":["Type","Audio"]},{"name":"Audio","tags":["Type","Audio","Core"]},{"name":"Video","tags":["Type","Video","Core"]},{"name":"Map","tags":["Type","Image"]},{"name":"Website","tags":["Type","Core","Website"]}];
var core = [];
var filterData = function(data){
for(var i=0;i<data.length;i++){
if (data[i].tags.indexOf("Core") > -1){
theList.push(data[i].name);
}
}
alltheterms = data;
core = theList
$scope.display = theList;
};
$scope.whatsmyname = function (value){
$scope.value = value;
theList = [];
for(var i=0;i<alltheterms.length;i++){
if (alltheterms[i].tags.indexOf(value) > -1){
theList.push(alltheterms[i].name);
}
}
var notAgain = theList.indexOf(value);
theList.splice(notAgain,1);
$scope.display=theList;
};
$scope.reset = function(){
$scope.display = core;
}
filterData(things);
}
我很困惑为什么简单的例子调用函数而更复杂的例子没有。请注意,在我的机器上,复杂的示例至少可以正确显示——我在将其转换为 plunker 时一定出错了。据我了解,这可能与范围有关,但我不知道到底发生了什么。任何建议(与此问题直接相关以及一般建议)将不胜感激。