角度搜索查询无法使用高级搜索

时间:2016-07-28 06:58:41

标签: angularjs filter angular-filters

我正在尝试使用角度查询在书籍对象的不同可用参数上创建高级搜索。

html是:

<div class="row row-height" ng-app='bookApp'>
    <div class="col-sm-12 login-col" style="margin-top: 2%;" ng-controller="BookSearchController">

        <div class=" row event-header" style="margin-bottom:12px;">
            <div class="col-sm-3">
                <label style="font-size:25px;" class="control-label">Book Search</label>
            </div>

        </div>

        <div class="input-group" id="adv-search">
                <input type="text" ng-model="query[queryBy]" class="form-control" placeholder="Search for Books" />
                <div class="input-group-btn">
                    <div class="btn-group" role="group">
                        <div class="dropdown dropdown-lg">
                            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false"><span class="caret"></span></button>
                            <div class="dropdown-menu dropdown-menu-right" role="menu">
                                <form class="form-horizontal" role="form">
                                  <div class="form-group">
                                    <label for="filter">Filter by</label>
                                    <select class="form-control" ng-model="queryBy">
                                        <option value="$" selected>All Books</option>
                                        <option value="title">Title</option>
                                        <option value="subject">Subject</option>
                                        <option value="authors">Authors</option>
                                        <option value="keywords">Keywords</option>
                                    </select>
                                  </div>


                                  <button type="submit" class="btn btn-primary"><i class="fa fa-search" aria-hidden="true"></i>
</button>
                                </form>
                            </div>
                        </div>
                        <button type="button" class="btn btn-primary"><i class="fa fa-search" aria-hidden="true"></i>
</button>
                    </div>
                </div>
            </div>


                 <table class="table table-bordered">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Title</th>
                        <th>Subject</th>
                        <th>Authors</th>
                        <th>Edition</th>
                        <th>Available</th>
                    </tr>
                </thead>
                <tbody class="">

                    <tr ng-repeat="book in books | filter:query track by $index">
                        <td>
                            <h4><span class="">{{$index + 1}}</span></h4>
                        </td>
                        <td>
                            <h4><span class="">{{book.title}}</span></h4>
                        </td>
                        <td>
                            <h4><span class="">{{book.subject}}</span></h4>
                        </td>
                        <td>
                            <h4 ng-repeat="a in book.authors">
                            <span > {{a.name}}</span>
                           </h4>
                        </td>
                        <td>
                            <h4><span class="">{{book.edition}}</span></h4>
                        </td>
                        <td>
                            <h4><span class="">

                            <span ng-show="book.availability">YES</span>
                            <span ng-show="!book.availability">NO</span>

                            </span></h4>
                        </td>


                    </tr>
                </tbody>
            </table>

    </div>
</div>

基本上,我想用搜索框构建查询&#39;查询&#39;并且下拉菜单选择了有价值的查询&#39;。

表格中的书籍列表包含以下格式的书籍对象:

[
    {
        "id": 47,
        "title": "Finance Management",
        "subject": "Finance",
        "ISBN": "4099",
        "publisher": {
            "id": 9,
            "name": "Kummanar123",
            "publication_year": 2014,
            "publication_place": "Kath"
        },
        "authors": [
            {
                "id": 10,
                "name": "Samir pathak"
            },
            {
                "id": 11,
                "name": "Suman sharma"
            }
        ],
        "edition": "2",
        "availability": true,
        "keywords": [
            {
                "text": "tax"
            },
            {
                "text": "finance"
            }
        ],
        "number_of_pages": 1111,
        "barcode": "2063"


     },
.
..
..

]

搜索与标题&#39;和&#39;主题&#39;这本书。但是,不与“作者”,“关键字”一起使用&#39;。 如何在book变量的内部对象中进行搜索?

1 个答案:

答案 0 :(得分:1)

尝试从$validation = new Validate(); if($validation->passed()) { //if success, insert(create) user try { $user = new User(); $salt = Crypt::salt(32); $user->insert(array( 'username' => Accept::get('username'), 'password' => Crypt::make(Accept::get('password'), $salt), 'salt' => $salt, 'name' => Accept::get('name') )); //After creation, redirect user header('Location : index.php'); exit(); } catch(Exception $e) { //otherwise display errors die("ERROR : CAN NOT REGISTER USER ".$e->getMessage()); } -

中删除[]
ng-model

<input type="text" ng-model="query" class="form-control" placeholder="Search for Books" /> -

中定义
controller

最后将$scope.query; 更改为

filter