4

我想将angular-drag-and-drop-lists与我自己的网格模板一起使用到 WYSIWYG 编辑器。如何构建我自己的 HTML 模板,ng-repeat这样它就可以在任何预定义的列中删除项目并将信息存储在$scope已删除的列项目中?

我想将丢弃的项目存储在columns数组中:

.controller('DragDropGrid', ['$scope',
function($scope) {
  $scope.layouts = {
    selected: null,
    templates: [
    {name: "Plugin", type: "item", id: 2},
    ],
    columns: [],
    oldaproachcolumns: [
        "A": [

        ],
        "B": [

        ]
      }
    ]
  };
}
]);

这目前不是一个工作模板。丢弃时会引发错误“未定义不是对象(评估'targetArray.splice')”:

<div ng-include="'grid.html'"></div>
<script type="text/ng-template" id="grid.html">
  <div class="col-md-12 dropzone box box-yellow">
    <div class="row template-grid" dnd-list="list">
      <div class="col-xs-12 col-md-8" ng-repeat="item in list" dnd-draggable="item" ng-include="item.type + '.html'">Header</div>
      <div class="col-xs-6 col-md-4">News</div>
    </div>
  </div>
</script>

<script type="text/ng-template" id="item.html">
  <div class="item">Plugin {{item.id}}</div>
</script>

这是标准的工作方法:

<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>

基于这个例子:demo

4

1 回答 1

0

如何在没有 ng-repeat 的情况下构建我自己的 HTML 模板

使用$templateCachefor循环作为替代:

var app = angular.module('foo', []);


function bop(model, data)
  {
  return data ? model : 'foo';
  }

function baz()
  {
  return bop;
  }

function foo($templateCache)
  {
  var i = 0, len = 5, bar = "";
  
  for (i; i < len; i++)
  	{
    bar = bar.concat("<li>",i,"<p ng-include=\u0022'foo'\u0022></p></li>");
    }
  
  $templateCache.put('listContent', bar);
  }

angular.module('foo').filter('baz', baz);
app.run(foo);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="foo">
  <script type="text/ng-template" id="foo">
    <span>hi</span>
  </script>
  <input ng-model="dude">
  <ul ng-include="'listContent' | baz:dude"></ul>
</div>

参考

于 2015-12-29T14:23:47.823 回答