Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如果JSON数组为空,如何禁用next和prev按钮?_Javascript_Angularjs_Html_Css - Fatal编程技术网

Javascript 如果JSON数组为空,如何禁用next和prev按钮?

Javascript 如果JSON数组为空,如何禁用next和prev按钮?,javascript,angularjs,html,css,Javascript,Angularjs,Html,Css,嗨,我正在使用AngularJS来获取像这样的JSON对象 "_embedded": { "incidents": [ { "id": 1, "name": "Golpe", "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been t

嗨,我正在使用AngularJS来获取像这样的JSON对象

 "_embedded": {
    "incidents": [
        {
            "id": 1,
            "name": "Golpe",
            "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
            "timestamp": "2015-01-01T00:00:00-0700",
            "upload_date": "-0001-11-30T00:00:00-0700",
            "archived": false,
            "_links": {
                "self": {
                    "href": "http://incidents-core/app_dev.php/incidents/1"
                },
                "attachments": {
                    "href": "http://incidents-core/app_dev.php/incidents/1/attachments"
                },
                "comments": {
                    "href": "http://incidents-core/app_dev.php/incidents/1/comments"
                },
                "thumbnail": {
                    "href": "http://incidents-core/app_dev.php/attachments/33/download"
                }
            },
            "_embedded": {
                "device": "Samsung 300",
                "employee": "Juan Lopez",
                "incident_type": "Golpe",
                "profile": "PruebaUpdate",
                "attachmentsCount": 7,
                "commentsCount": 15
            }
        },
现在,我使用引导模式窗口来显示所有对象,并为下一个和上一个对象创建了此方法。(由于某些原因,当我单击下一个时,此方法可以正常工作,但当我单击上一个时,从2开始,当im位于[0]位置的对象时,代码为[-2])

阵列为空时,如何禁用按钮? 这是我的模态windows代码:

<!-- Modal -->
<div class="modal fade  bs-example-modal-lg" id="incidentModal" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">Incident Name: {{incidentSelected.name}}</h4>
                <button id="prev" class="btn btn-success" type="submit" ng-click="prevIncident()">Previous</button>
                <button id="next" class="btn btn-success" type="submit" ng-click="nextIncident()">Next</button>
            </div>
            <!-- /.modal-header -->
            <!--/.modal-header -->
            <div class="modal-body">
                <div class="container-fluid">
                    <div class="modal-body row">
                        <div class="col-lg-6">
                            <p class="nocommnts-alert" ng-show="!attachmensresults.length">There are no attachments!</p>
                            <div class="attachmentlist">
                                <ul ng-repeat="image in images | filter:query as attachmensresults">
                                    <li>
                                        <a href="{{image._links.file.href}}" data-lightbox="example-set" data-title="Click the right half of the image to move forward.">
                                            <div class="img-preview">
                                                <img ng-src="{{image._links.file.href}}" alt="" />
                                            </div>
                                        </a>
                                    </li>
                                </ul>
                            </div>
                            <!-- /.attachmentlist -->
                        </div>
                        <!-- /.col-lg-6 -->
                        <div class="col-lg-6">
                            <label>Category: </label> {{ incidentSelected._embedded.incident_type}}
                            <br />
                            <label>Description: </label>
                            <div class="Incidentdescrptn">
                                {{ incidentSelected.description }}
                            </div>
                            <br />
                            <label>Employee: </label> {{ incidentSelected._embedded.employee }}
                            <br />
                            <label>Date of Incident: </label> {{incidentSelected.timestamp | date:'EEE'}}{{incidentSelected.timestamp | date:' - dd/mm/yyyy'}}
                            <br />
                            <label>Hour of Incident: </label> {{incidentSelected.timestamp | date:'hh:mm:ss a'}}
                            <br />
                            <label>Device: </label> {{incidentSelected._embedded.device}}
                            <br />
                            <button type="button" class="btn btn-default" data-toggle="modal" href="#stack2"><span class="glyphicon glyphicon-envelope"></span> Send by Email</button>
                            <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-trash"></span> Archive</button>
                        </div>
                        <!-- /.col-lg-6 -->
                    </div>
                    <!-- .modal-body row -->
                    <div class="clearfix"></div>
                    <div class="commntSection">
                        <div class="row">
                            <div class="span4 collapse-group">
                                <p><b>{{commntresults.length}}</b> Comments</p>
                                <div class="collapse" id="viewdetails">
                                    <p class="nocommnts-alert" ng-show="!commntresults.length">There are no comments!</p>
                                    <div class="col-sm-12">
                                        <div id="commnts" ng-repeat="comment in comments | filter:query as commntresults">
                                            <div class="avatar-frame">
                                                <img src="img/grumpy.jpg" alt="" />
                                            </div>
                                            <div class="commnt_cont">
                                                <b>User:</b>
                                                <p>{{comment.message}}</p>
                                            </div>
                                            <!-- ./commnt_cont -->
                                            <br />
                                            <div class="line-separator"></div>
                                            <br />
                                        </div>
                                        <!-- /#commnts -->
                                    </div>
                                    <!-- ./col-sm-12 -->
                                </div>
                                <!-- ./collapse -->
                                <a class="btn showdetails" data-toggle="collapse" data-target="#viewdetails"></a>
                                <div class="row">
                                    <div class="col-sm-12">
                                        <form ng-submit="processForm()">
                                            <div class="form-group">
                                                <textarea ng-keyup="$event.keyCode == 13 ? processForm() : null" required ng-model="formData.comment.message" class='autoExpand' rows='1' data-min-rows='1' id="message" placeholder="Write a comment.... :)"></textarea>
                                            </div>
                                            <!-- /.form-group -->
                                            <button class="btn btn-primary" type="submit"><span class="glyphicon glyphicon-heart"></span> Comment</button>

                                        </form>
                                    </div>
                                    <!-- /.col-sm-12 -->
                                </div>
                                <!-- /.row -->
                            </div>
                            <!-- /.collapse-group -->
                        </div>
                        <!-- /.row -->
                    </div>
                    <!-- /.commntSection -->
                </div>
                <!-- /.container-fluid-->
            </div>
            <!-- /.modal-body-->
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
            <!-- /.modal-footer -->
        </div>
        <!-- /.modal-content-->
    </div>
    <!-- /.modal-dialog modal-lg-->
</div>
<!-- /.modal fade  bs-example-modal-lg -->

&时代;
事件名称:{{incidentSelected.Name}
以前的
下一个
没有附件

类别:{incidentSelected.\u embedded.incident\u type}
说明: {{incidentSelected.description}
员工:{{incidentSelected.\u embedded.Employee}}
事件日期:{{incidentSelected.timestamp}日期:'EEE'}{{incidentSelected.timestamp}日期:'-dd/mm/yyyy'}
事件发生时间:{{incidentSelected.timestamp}日期:'hh:mm:ss a'}
设备:{incidentSelected.\u embedded.Device}
通过电子邮件发送 档案文件 {{commntresults.length}}注释

没有评论

用户: {{comment.message}}



评论 接近
在使用引导时,还可以使用指令将禁用的类应用于按钮

<button ng-class="{disabled:incidents.length===0}" ...

在使用引导时,还可以使用指令将禁用的类应用于按钮

<button ng-class="{disabled:incidents.length===0}" ...

在使用引导时,还可以使用指令将禁用的类应用于按钮

<button ng-class="{disabled:incidents.length===0}" ...

在使用引导时,还可以使用指令将禁用的类应用于按钮

<button ng-class="{disabled:incidents.length===0}" ...
使用
ng disabled=“events.length==0”
使用
ng disabled=“events.length==0”
使用
ng disabled=“events.length==0”
使用
ng disabled=“events.length==0”
ng disabled=“events.length==0”
ng disabled=“events.length==0”
ng disabled=“events.length==0”
ng disabled=“events.length==0”