2016-03-08 80 views
0

我是Laravel和Angularjs的新手。我想就如何解決這個問題提供一些幫助。國家對象不顯示

角控制器功能

var loadTables = function(){ 
      tableService.all(1,20) 
       .success(function(response){ 
        console.log(response); 
        $scope.tables = response.data; 
        $scope.towns=response.town; 
        $scope.countrys=response.country; 
        $scope.package_lists=response.package_list; 
        $scope.categories=response.categories; 

Laravel

$id = Auth::user()->id; 
    $packages = User::find($id)->packages; 
    //$packages=$packages->paginate(Input::get('perPage'))->toArray(); 
    $countries = Country::lists('name', 'id'); 
    $towns = Town::lists('name', 'id'); 
    $categories = Category::lists('name', 'id'); 
    $package_list=$packages->lists('name','id'); 
    $packages->load('country'); 



    return (['data'=>$packages,'town'=>$towns, 'categories'=>$categories, 'package_list'=>$package_list]); 

查看

<option ng-repeat="country in countrys" value="@{{country.id}}">@{{country.name}}</option> 

1.國家v視圖中不顯示線索。我如何去做這件事。

<div ng-controller="tableController"> 
<a class="add-link btn btn-success" ng-click="toggleForm()" ng-  hide="showForm">Add Packages</a> 
<table class="table table-striped breathe" ng-hide="showForm"> 
    <thead> 
     <tr><th>Name</th><th>About</th><th>status</th><th>Image</th> <th>Action</th></tr>       
    </thead> 
    <tbody> 
    <tr ng-repeat="table in tables"> 
     <td>@{{table.name}}</td> 
     <td>@{{table.short_description}}</td> 
     <td>@{{table.status}}</td> 
     <td><img width="120" heigth="72" ng- src="@{{getImageSource(table.image)}}"/></td> 
    <td> 
     <button class="btn btn-sm btn-warning" ng- click="editTable(table.id)">Edit</button> 
     <button class="btn btn-sm btn-danger" ng- click="deleteTable(table.id, currentPage, $index)">Delete</button> 
     </td></tr> 
    </tbody> 
</table> 
<ul class="pagination" ng-hide="showForm"> 
    <li ng-class="{'disabled':currentPage==1}"><a ng- click="loadFirstPage()">&laquo;</a></li> 
    <li ng-repeat="page in pages" ng-class="{'active':page==currentPage}"><a ng-click="loadNthPage(page)">@{{page}}</a></li> 
    <li ng-class="{'disabled':currentPage==lastPage}"><a ng-click="loadLastPage()">&raquo;</a></li> 
</ul> 
<form name="tablesForm" ng-show="showForm" class="col-md-4" enctype="multipart/form-data"> 
    <div class="form-group"> 
     Name<input type="text" name="number" ng-model="newName" class="form- control" required> 
     <em class="muted" ng-show="tablesForm.available.$pristine && tablesForm.available.$invalid">Required</em> 
    </div> 
    <div class="form-group"> 
     Avarage Price<input type="text" name="seats" ng-model="newPrice" class="form-control" required> 
     <em class="muted" ng-show="tablesForm.available.$pristine && tablesForm.available.$invalid">Required</em> 
    </div> 
    <div class="form-group"> 
     Short Description<input type="text" name="position" ng- model="newShort_description" class="form-control"> 
    </div> 
<div class="form-group"> 
    Description<input type="textarea" name="description" ng-model="newDescription" class="form-control"> 
</div> 
<div class="form-group"> 
    Category<select type="text" id="category" ng-model="newCategory" class="form-control" required> 
    <option ng-repeat="category in categories" value="@{{category.id}}">@{{category.id}}</option> 
    </select> 
    <em class="muted" ng-show="tablesForm.available.$pristine && tablesForm.available.$invalid">Required</em> 
</div> 
<div class="form-group"> 
    Country<select type="text" name="country" ng-model="newCountry" class="form-control" required> 
    <option ng-repeat="country in countrys" value="@{{country.id}}">@{{country.name}}</option> 
    </select> 
    <em class="muted" ng-show="tablesForm.available.$pristine && tablesForm.available.$invalid">Required</em> 
</div> 
<div class="form-group"> 
    Town<select type="text" name="town" ng-model="newTown" class="form-control" required> 
    <option ng-repeat="town in towns" value="@{{town.id}}">@{{town.name}}</option> 
    </select> 
    <em class="muted" ng-show="tablesForm.available.$pristine && tablesForm.available.$invalid">Required</em> 
</div> 
<div class="form-group"> 
    <img width="120" height="82" ng-src="@{{newThumbnail}}" ng-show="showEdit" style="display: block;" /> 
    Image<input type="file" name="thumbnail" ng-file-select="onFileSelect($files)"> 
</div> 
<div class="form-group"> 
    <button class="btn btn-primary" ng-hide="showEdit" ng-click="tablesForm.$valid &&addNewTable(newNumber,newSeats,newPosition,newDescription,newAvailable, currentPage)">Add new table</button> 
    <button class="btn btn-primary" ng-show="showEdit" ng-click="tablesForm.$valid && updateTable(tableId, newNumber,newSeats,newPosition,newDescription,newAvailable)">Update table</button> 
    <button class="btn btn-danger" ng-show="showForm" ng-click="toggleForm()">Cancel</button> 
</div> 

+0

你在哪裏返回'國家/什麼是'response.country'? –

+0

已更正,但仍未顯示選擇選項中的值。事實上不僅僅是國家,還包括城鎮和類別。 – patrickkevins

回答

0

你沒有響應列表上返回國家

試試下面的代碼:

return (['data'=>$packages,'town'=>$towns, 'country':$countries, 'categories'=>$categories, 'package_list'=>$package_list]); 

編輯:根據您的意見,它表明你」將數據作爲對象返回,而不是數組。爲了讓Angular遍歷數據,它應該存儲在一個數組中。

+0

感謝您的確認,但與鎮和類別的情況相同。 select-option顯示爲數組分配的插槽,但不顯示值。但在控制檯上,我看到所有返回的對象和值 – patrickkevins

+0

您可以告訴我console.log到您的迴應? – Nathan

+0

Object {data:Array [1],town:Object,countries:Object,categories:Object,package_list:Object} 1 tableController.js:43:7 – patrickkevins