选择 - 选项和输入日期不是由JavaScript

时间:2018-01-11 15:07:29

标签: javascript html angularjs node.js

我在将数据从数据库设置为我的选择和HTML文件中的输入(日期和文本已经尝试过)时出现问题。有什么遗漏或有什么不对吗?

以下是我的导入:

    <script src="js/moment.js"></script>
    <script src="js/moment.de.js"></script>

    <script src="js/jquery-3.2.1.min.js"></script>
    <script src="js/jquery-ui.min.js"></script>

    <script src="js/select2.full.min.js"></script>

    <script src="js/angular.min.js"></script>
    <script src="js/angular-route.min.js"></script>
    <script src="js/angular-filter.min.js"></script>

    <script src="js/popper.min.js"></script>
    <script src="js/transition.js"></script>
    <script src="js/collapse.js"></script>
    <script src="js/bootstrap-datepicker.min.js"></script>

这里是html部门:

<table class="table mb-1">
                <thead>
                    <tr>
                        <th scope="col"> </th>
                        <th scope="col"> </th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <th scope="row">Beobachten</th>
                        <td>
                            <select id="selectTracking" ng-model="tracking" class="wdselect">
                                <option ng-value="0">Nein</option>
                                <option ng-value="1">Ja</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">Ansprache</th>
                        <td>
                            <select id="selectRequest" ng-model="request" class="wdselect">
                                <option ng-value="0">Nein</option>
                                <option ng-value="1">Ja</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">Response</th>
                        <td>
                            <select id="selectResponse" ng-model="response" class="wdselect">
                                <option ng-value="0">Nein</option>
                                <option ng-value="1">Ja</option>
                            </select>
                        </td>
                    </tr>
                    <tr ng-if="response == 1">
                        <th scope="row"> </th>
                        <td>
                            <select id="selectResponseValue" ng-model="responseVal" class="wdselect" onchange="setResponseVal(this.value)">
                                <option ng-value="0">Negativ</option>
                                <option ng-value="1">Positiv</option>
                            </select>
                        </td>
                    </tr>
                </tbody>
            </table>

            <div class="input-group date">
                <div class="input-group-addon alert-info">Research</div>
                <input type='text' id="research" class="form-control" placeholder="dd.mm.yyyy" />
                <span class="input-group-addon">
                    <span class="oi oi-calendar"></span>
                </span>
            </div>

Browser shows the select-items correct with the id as value and name

在我的JavaScript中,我使用从NodeJS获得的值设置值

    /**
     * get Candidate-data to fill into Form for updating selected Team
     */
    $http.post('candidate/info', { candidateid: $routeParams.candidateid }).then(function (response) {
        $scope.candidate = response.data.data.candidate;
        $scope.sources = response.data.data.sources;
        $scope.teams = response.data.data.teams;
        $scope.citys = response.data.data.citys;
        $scope.sourcer = response.data.data.sourcer;

        $scope.iserrmessage = !response.data.sucess;
        $scope.message = response.data.message;

        $scope.tracking;
        $scope.request;
        $scope.response;
        $scope.responseVal;

        $scope.research = toLocalDate($scope.candidate.research);

        var research = $('#research');

        research.datetimepicker();
        research.data('DateTimePicker').date($scope.research);
        research.on('dp.change', function (e) {
            $scope.candidate.research = e.date;
        });


        var selectTracking = $('#selectTracking');
        selectTracking.select2();

        var selectRequest = $('#selectRequest');
        selectRequest.select2();

        var selectResponse = $('#selectResponse');
        selectResponse.select2();

        selectTracking.val($scope.candidate.tracking);
        selectTracking.trigger("change");
        selectTracking.on("select2:select", function (e) {
            var id = selectTracking.val();
            $scope.tracking = id;
        });

        selectRequest.val($scope.candidate.request);
        selectRequest.trigger("change");
        selectRequest.on("select2:select", function (e) {
            var id = selectRequest.val();
            $scope.request = id;
        });

        selectResponse.val($scope.candidate.response);
        selectResponse.trigger("change");
        selectResponse.on("select2:select", function (e) {
            var id = selectResponse.val();
            $scope.response = id;
        });

    });//end candidate/info

我的NodeJS中的代码:

        /**
         * Kandidat Infos anzeigen - candidateDetail
         */
        app.post('/candidate/info', function (req, res) {
            if (req.session.userid) {
                var parameter = [req.body.candidateid];
                var candidatequery = "SELECT candidate.id, candidate.firstname as firstname," +
                    "CASE WHEN candidate.lastname IS NULL THEN '' ELSE candidate.lastname END AS lastname," +
                    "sources.name as source, candidate.source_id as source_id, candidate.source_text, candidate.eR," +
                    "CASE WHEN candidate.intern = '0000-00-00' THEN '-' ELSE candidate.intern END AS intern," +
                    "CASE WHEN candidate.extern = '0000-00-00' THEN '-' ELSE candidate.extern END AS extern," +
                    "CASE WHEN candidate.hire = '0000-00-00' THEN '-' ELSE candidate.hire END AS hire," +
                    "CASE WHEN candidate.telnotice = '0000-00-00' THEN '-' ELSE candidate.telnotice END AS telnotice," +
                    "CASE WHEN candidate.response_value = null THEN '-' ELSE candidate.response_value END AS response_value," +
                    "candidate.tracking, candidate.request, candidate.response," +
                    "city_group.city, team.name as teamname, candidate.research, candidate.date, users.firstname as sourcerName, candidate.sourcer " +
                    "FROM candidate LEFT JOIN sources ON candidate.source_id = sources.id " +
                    "LEFT JOIN team ON team.id = candidate.team_id " +
                    "LEFT JOIN city_group ON team.city_group = city_group.id " +
                    "LEFT JOIN users ON candidate.sourcer = users.id " +
                    "WHERE candidate.id = ?";

                var sourcequery = "SELECT id, name FROM sources WHERE active=1";
                var teamquery = "SELECT team.id, team.name, team.city_group, city_group.city FROM team " +
                    "LEFT JOIN city_group ON team.city_group = city_group.id " +
                    " WHERE team.active=1";
                var cityquery = "SELECT id, city FROM city_group";
                var userquery = "SELECT id, firstname, lastname FROM users WHERE active=1";

                    db.query(candidatequery, parameter, function (err, rows, fields) {
                        if (err) throw err;

                        if (rows.length == 0) {
                            sendResponse(res, false, "Kandidat nicht gefunden!");
                        } else {
                            db.query(sourcequery, function (sourceerr, sourcerows, sourcefields) {
                                if (sourceerr) throw sourceerr;

                                db.query(teamquery, function (teamerr, teamrows, teamfields) {
                                    if (teamerr) throw teamerr;

                                    db.query(cityquery, function (cityerr, cityrows, cityfields) {
                                        if (cityerr) throw cityerr;

                                        db.query(userquery, function (usererr, userrows, userfields) {
                                            if (usererr) throw usererr;

                                            var result = {
                                                candidate: rows[0],
                                                sources: sourcerows,
                                                teams: teamrows,
                                                citys: cityrows,
                                                sourcer: userrows
                                            };

                                            sendResponse(res, true, "", result); 

                                        });//end userquery
                                    });//end cityquery
                                });//end teamquery
                            });//end sourcequery  
                        }//end Kandidat gefunden
                    });//end db.query(candidatequery)

            } else {
                sendResponse(res, false, "Kein Benutzer eingeloggt!");
            }
        }); //end candidate/info

我使用谷歌浏览器,在开发人员视图中我可以看到值被发送到浏览器(如下图所示),但是选择不显示该选项。

Developer-View in the Browser (all data is received - but not displayed)

我的输入日期字段也有同样的问题。 我有来自数据库的数据,但我无法将其设置为输入字段。没有错误消息,它只是不起作用。

2 个答案:

答案 0 :(得分:0)

尝试在下面的表单中包装html代码

  <form ng-submit="submitFunction()">
    <div class="input-group mb-1">
      <div class="input-group-addon alert-info">Source</div>
         <select class="custom-select wdselect" id="selectSource"
          ng-model="sourceSelect"
          ng-change="showSourceValue(sourceSelect)">
           <option ng-repeat="s in sources" ng-value="{{s.id}}">
              {{s.name}}
           </option>
         </select>
      </div>
  </form>

答案 1 :(得分:-1)

那么,您无法设置从数据库ryt检索的所选数据? 试试这种方式。

$scope.sourceSelect={
"name":ResopnseObj.source,
"id":ResponseObj.id
}