0

我收到此错误; Cannot read property '0' of null (对于'0','1','2','3'......等)在我一天中的每个24小时内一次。然后是第 8 行、第 9 行、第 10 行和第 11 行,我在日历上有事件。

屏幕截图 2016-06-02 在 1 35 39 pm

这是我的日历日视图模板

<table ui-tree="treeOptions">
    <tbody>
    <!-- Builds Day View with one <tr> for each hour(24 hrs) in rows model --> 
    <tr ng-repeat="tm in rows track by $index" ng-model="rows" ui-tree-nodes="">
        <td class="calendar-cell" ui-tree-node>
            <!-- hourTouch() counts the touch events, once shows <p>Signup</p>, twice  -->
            <!-- shows <div class="finish-time"> which is my draggable element -->
            <!-- tm.events is an array of objects with the event detail properties -->
            <div class="add_event_shade" 
                    ng-if="tm.events" 
                    on-touch="hourTouch($event)"
                    ng-model="tm.events"
                    ui-tree-nodes="">
                <p style="display:none;" 
                     ng-model="volunteerStart">
                     Signup
                </p>
                <div class="finish-time"
                        style="display:none";
                        ui-tree-node>
                        Finish: {{ displayEnd}}
                </div>
            </div>
            <div ng-class="{'calendar-event-wrap': tm.events}"
                    ng-show="tm.events">
                <!-- adds events to the calendar day view -->
                <div ng-repeat="displayEvent in tm.events" 
                       class="calendar-event"
                       ng-click="eventSelected({event:displayEvent.event})"
                    <div class="calendar-event-inner"></div>
                </div>
            </div>
        </td>
    </tr>
    </tbody>
</table>

在我的控制器中,我有我的 html 注释中描述的逻辑以及文档中显示的全套$scope.treeOptions = { accept, beforeDrag, removed等。

我是否遗漏了一些我需要在控制器端做的事情,或者我在模板上设置了错误的 ui-tree 属性?

4

2 回答 2

1

我不得不ng-model="rows" ui-tree-nodes=""从第一个移动<tr><tbody>. 然后ui-tree-node从第一个<td>到它的父级<tr>

然后进一步向下移动ng-model="tm.events" ui-tree-nodes=""<div class="add_event_shade">其父级<td>并将 更改ng-model="tm.events"ng-model="rows"。HTML 如下所示。

这修复了上面显示的错误,我可以拖动元素。虽然我仍然在拖动元素在视图中移动我的事件时遇到其他问题,但拖动的元素在拖动时不可见,并且我无法放下拖动的元素。但我想这些是另一个问题的事情。

<table ui-tree="treeOptions">
    <tbody ng-model="rows" ui-tree-nodes="">
    <!-- Builds Day View with one <tr> for each hour(24 hrs) in rows model --> 
        <tr ng-repeat="tm in rows track by $index" ui-tree-node>
            <td class="calendar-cell" ng-model="rows" ui-tree-nodes="">
            <!-- hourTouch() counts the touch events, once shows <p>Signup</p>, twice  -->
            <!-- shows <div class="finish-time"> which is my draggable element -->
            <!-- tm.events is an array of objects with the event detail properties -->
            <div class="add_event_shade" 
                 ng-if="tm.events" 
                 on-touch="hourTouch($event)">
                <p style="display:none;" 
                   ng-model="volunteerStart">
                   Signup
                </p>
                <div class="finish-time"
                     style="display:none";
                     ui-tree-node>
                     Finish: {{ displayEnd}}
                </div>
            </div>
            <div ng-class="{'calendar-event-wrap': tm.events}"
                 ng-show="tm.events">
                    <!-- adds events to the calendar day view -->
                    <div ng-repeat="displayEvent in tm.events" 
                         class="calendar-event"
                         ng-click="eventSelected({event:displayEvent.event})"
                        <div class="calendar-event-inner"></div>
                    </div>
                </div>
            </td>
        </tr>
    </tbody>
</table>
于 2016-06-03T15:02:28.980 回答
1
<table ui-tree="treeOptions">
<tbody ui-tree-nodes data-max-depth="2" ng-model="row">
<!-- Builds Day View with one <tr> for each hour(24 hrs) in rows model --> 
<tr ng-repeat="tm in rows track by $index" ng-model="rows" ui-tree-node>
    <td class="calendar-cell">
        <!-- hourTouch() counts the touch events, once shows <p>Signup</p>, twice  -->
        <!-- shows <div class="finish-time"> which is my draggable element -->
        <!-- tm.events is an array of objects with the event detail properties -->
        <div class="add_event_shade" 
                ng-if="tm.events" 
                on-touch="hourTouch($event)"
                ng-model="tm.events"
                ui-tree-nodes="">
            <p style="display:none;" 
                 ng-model="volunteerStart">
                 Signup
            </p>
            <div class="finish-time"
                    style="display:none";
                    ui-tree-node>
                    Finish: {{ displayEnd}}
            </div>
        </div>
        <div ng-class="{'calendar-event-wrap': tm.events}"
                ng-show="tm.events">
            <!-- adds events to the calendar day view -->
            <div ng-repeat="displayEvent in tm.events" 
                   class="calendar-event"
                   ng-click="eventSelected({event:displayEvent.event})"
                <div class="calendar-event-inner"></div>
            </div>
        </div>
    </td>
</tr>
</tbody>

选项设置如下。

    $scope.treeOptions= {
        accept: function(sourceNodeScope, destNodesScope, destIndex) {
            return sourceNodeScope.$parent.$id === destNodesScope.$id;
        },
        dropped: function(event) {
          return true;
        },
        beforeDrop: function(event) {
           return true;
        }
    };

数据格式如下

   $scope.row = [{id:'', ..... //JSON data }]
于 2017-04-21T10:06:20.660 回答