Javascript 如何在不重复ng的情况下制作模板,并使用角度拖放列表将数据传递到$scope?
我想与我自己的网格模板一起使用WYSIWYG编辑器。如何在不使用Javascript 如何在不重复ng的情况下制作模板,并使用角度拖放列表将数据传递到$scope?,javascript,angularjs,angularjs-scope,angular-dragdrop,Javascript,Angularjs,Angularjs Scope,Angular Dragdrop,我想与我自己的网格模板一起使用WYSIWYG编辑器。如何在不使用ng repeat的情况下构建自己的HTML模板,以便它能够在任何预定义列中删除项目,并将信息存储在已删除列项目的$scope中 我想在列数组中存储丢弃的项目: .controller('DragDropGrid', ['$scope', function($scope) { $scope.layouts = { selected: null, templates: [ {name: "Plugin",
ng repeat
的情况下构建自己的HTML模板,以便它能够在任何预定义列中删除项目,并将信息存储在已删除列项目的$scope
中
我想在列
数组中存储丢弃的项目:
.controller('DragDropGrid', ['$scope',
function($scope) {
$scope.layouts = {
selected: null,
templates: [
{name: "Plugin", type: "item", id: 2},
],
columns: [],
oldaproachcolumns: [
"A": [
],
"B": [
]
}
]
};
}
]);
这当前不是一个工作模板。在drop时,它抛出错误“undefined不是对象(计算'targetArray.splice')”:
标题
新闻
插件{{item.id}
这是标准的工作方法:
<div class="row">
<div ng-repeat="(zone, list) in layouts.oldaproachcolumns" class="col-md-3">
<div class="dropzone box box-yellow">
<h3>{{zone}}</h3>
<div ng-include="'list.html'"></div>
</div>
</div>
</div>
<script type="text/ng-template" id="list.html">
<ul dnd-list="list">
<li ng-repeat="item in list" dnd-draggable="item" dnd-effect-allowed="move" dnd-moved="list.splice($index, 1)" dnd-selected="layouts.selected = item" ng-class="{selected: layouts.selected === item}" ng-include="item.type + '.html'">
</li>
</ul>
</script>
{{zone}}
-
基于此示例:
如何在不重复ng的情况下构建自己的HTML模板
使用$templateCache
和for
循环作为替代:
var-app=angular.module('foo',[]);
功能bop(型号、数据)
{
返回数据?模型:“foo”;
}
函数baz()
{
回油防喷器;
}
函数foo($templateCache)
{
变量i=0,len=5,bar=“”;
对于(i;i”,i“”
”;
}
$templateCache.put('listContent',bar);
}
角度。模块('foo')。过滤器('baz',baz);
app.run(foo)代码>
你好
你能用这个做一个JS小提琴吗?看起来您的目标数组没有定义,这就是代码无法工作的原因。
<div class="row">
<div ng-repeat="(zone, list) in layouts.oldaproachcolumns" class="col-md-3">
<div class="dropzone box box-yellow">
<h3>{{zone}}</h3>
<div ng-include="'list.html'"></div>
</div>
</div>
</div>
<script type="text/ng-template" id="list.html">
<ul dnd-list="list">
<li ng-repeat="item in list" dnd-draggable="item" dnd-effect-allowed="move" dnd-moved="list.splice($index, 1)" dnd-selected="layouts.selected = item" ng-class="{selected: layouts.selected === item}" ng-include="item.type + '.html'">
</li>
</ul>
</script>