【问题标题】:How do I get the data from a view to another view in ionic?如何在 ionic 中将数据从视图获取到另一个视图?
【发布时间】:2016-04-29 18:13:50
【问题描述】:

我已经按照这个教程ionic/angular - get data from database - data loaded, but no output on site 关于如何从数据库中检索数据并在 ionic 中显示它,但问题是数据只能在一个视图中看到,我不知道如何在另一个视图中查看它

screencap - 我已经成功地从我的数据库中显示了我的 ionic 中的食谱,当我点击钢笔图标时,它应该会显示食谱名称、成分等等

screencap 2 - 但是当我点击它时它不显示任何数据。

这是我查看数据的代码:

user_model.php(codeigniter - 模型)

public function user_recipe_data()
    {
        $this->db->select('*');
        $this->db->from('usersrecipes');
        $this->db->join('user', 'user.user_id = usersrecipes.user_id');
        $this->db->where('usersrecipes.user_id = 12 ');
        $query = $this->db->get();
        return $query->result_array();
    }

Main.php (codeigniter - 控制器)

public function get_user_recipe_data()
{
    $postdata = json_decode(file_get_contents("php://input"));
    $user_recipe = $this->User_model->user_recipe_data();
    echo json_encode($user_recipe);
}

RecipeService.js(离子)

.factory('getRecipeService', function($http){

return {
    all: function() {
      return $http.get("http://localhost/admin-recipick/api/Main/get_user_recipe_data");
    },
    get: function(Recipe_ID) {
        q = $http.get("http://localhost/admin-recipick/api/Main/get_user_recipe_data");
  for (var i = 0; i < q.length; i++) {
    if (q[i].id === parseInt(Recipe_ID)) {
      return q[i];
    }
  }
  return null;
}
};

});

controller.js(离子)

 getRecipeService.all().then(function(payload) {
 $scope.userrecipedata = payload.data;
 console.log(payload);
});

profile.html(离子)

 <ion-list>
              <ion-item ng-repeat="recipe in userrecipedata" class="item-remove-animate item-avatar item-icon-right"  type="item-textu-wrap" href="#/app/recipes/{{recipe.Recipe_ID}}">
                <img ng-src="img/food/porkmenudo.jpg">

                <h2>{{recipe.Recipename}}</h2>
                <p>{{recipe.Ingredients}}</p>
                <i class="icon ion-edit"></i>
                <ion-option-button class="button-assertive" ng-click="remove(recipe)">
                  Delete
                </ion-option-button>
              </ion-item>
            </ion-list>

recipe-detail.html ( ionic - 在这个 html 中我也想在这里显示数据,但它在输入类型中没有显示任何数据。我该怎么办?)

    <div class="list">

        <label class="item item-input">
          <span class="input-label">Index Name</span>
            <input type="text" ng-model="recipe.Recipe_ID">
        </label>
        <label class="item item-input">
           <span class="input-label">Recipe Name</span>
             <input type="text" ng-model="recipe.Recipename">
         </label>
         <label class="item item-input">
            <span class="input-label">Ingredients</span>
              <input type="text" ng-model="recipe.Ingredients">
         </label>
         <label class="item item-input item-select">
            <span class="input-label">Cooking Time</span>
              <select ng-model="recipe.Cookingtime">
                 <option value="20mins">20mins</option>
                 <option value="30mins">30mins</option>
                 <option value="1hr">1hr</option>
               </select>
          </label>
          <label class="item item-input">
              <textarea placeholder="PROCEDURE" rows="12" ng-model="recipe.Procedure">
              </textarea>
          </label>
           <button class="button button-block button-assertive h1" ng-click="AddRecipe()">Update Recipe</button>
          </div>

【问题讨论】:

    标签: php angularjs ajax codeigniter ionic-framework


    【解决方案1】:

    控制器使用http

    .controller('Ctrl', function($scope, $http, $stateParams) {
    $scope.userrecipedata = [];
    
    $http.get('http://localhost/admin-recipick/api/Main/get_user_recipe_data').success(function(response){
        $scope.userrecipedata = response;
    }); 
    })
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-29
    • 1970-01-01
    • 2021-11-09
    • 1970-01-01
    • 1970-01-01
    • 2011-03-01
    • 1970-01-01
    相关资源
    最近更新 更多