如何从ng-repeat发送数据?

时间:2017-06-15 06:28:00

标签: javascript angularjs

我列出了一些清单,列表上的日期从最新日期到最后30天。我想发送日期到webservice。但它始终是未定义的变量。我的代码就像这样

HTML

$result = $wpdb->get_col( "SELECT slug FROM {$wpdb->prefix}terms WHERE name = '$term'" );

$term_slug = ( !empty( $result ) ) ? $result[0] : $term;


$query = "SELECT postmeta.post_id AS product_id
            FROM {$wpdb->prefix}postmeta AS postmeta
                LEFT JOIN {$wpdb->prefix}posts AS products ON ( products.ID = postmeta.post_id )
            WHERE postmeta.meta_key LIKE 'attribute_%'
                AND postmeta.meta_value = '$term_slug'
                AND products.post_parent = $product->id";

$variation_id = $wpdb->get_col( $query );

$parent = wp_get_post_parent_id( $variation_id[0] );

if ( $parent > 0 ) {
    $_product = new WC_Product_Variation( $variation_id[0] );
    return $term . ' (' . woocommerce_price( $_product->get_price() ) . ')';
}
return $term;

JS

   <ion-list> 
       <ion-item class="animate-repeat" ng-repeat="name in rep">
            <div>            
                <select ng-options="size as size.code for size in sizes"
                        ng-model="item"
                        style="background-color:#262261;color: white"
                        ng-change="update(item)">
                </select>
            </div>   
            <!--{{name | date: "y-MM-dd"}}-->
            {{name}}
            <button type="submit" class="button button-block"
                    id="buttonblue" ng-click="tracking()">
                <font color="white" size="4">Tracking</font>
            </button>
        </ion-item>
    </ion-list>

我想发送数据$scope.rep = []; for (var i=0; i < 31; i++) { $scope.item = {}; $scope.code = {}; $scope.sizes = [{code: 123456789, name: 'Modul 1'}, {code: 864369038803163, name: 'Modul 2'}, {code: 864369038796946, name: 'Modul 4'}, {code: 864369038803833, name: 'Modul 5'}, {code: 864369038816645, name: 'Modul 6'}, {code: 864369038797142, name: 'Modul 7'}, {code: 864369038796698, name: 'Modul 8'}]; $scope.update = function (selected) { $scope.item = selected; }; $scope.trip = new Date(); $scope.besok =new Date($scope.trip.getTime() - i*(24*60*60*1000)); $scope.rep.push($scope.besok); $scope.tracking = function () { kaka.list($scope.item.code, $scope.name).success(function (data) { console.log(data); console.log($scope.name); }); }; } ,但在console.log中始终显示$scope.name。我不知道如何从我的列表中发送日期。请帮我解决我的问题。 感谢

1 个答案:

答案 0 :(得分:2)

ng-repeat创建sub-scope,因此变量name仅在模板的ng-repeat块中可用,但根据您的情况,您可以将name作为参数传递tracking如下所示:

<button type="submit" class="button button-block" id="buttonblue" ng-click="tracking(name)">
  <font color="white" size="4">Tracking</font>
</button>

$scope.tracking = function (name) {
    // use name instead of $scope.name
    kaka.list($scope.item.code, name).success(function (data) {
        console.log(data);
        console.log(name);
    });
};