我已经为我的 AngularJS 应用程序创建了一个简单的 PHP 函数。我想选择默认选项,它应该是可见的。不幸的是,它没有选择我想要的值。
我的函数如下:
function qtyList($selectName, $selectQty){
$str = '<select ng-model="qty" ng-change="updateCart('.$selectName.',qty)">';
for($i=1; $i<=100; $i++){
if($selectQty == $i)
$str .= '<option ng-selected="selected">'.$i.'</option>';
else
$str .= '<option>'.$i.'</option>';
}
$str .= '</select>';
return $str;
}
请提供任何建议。
最佳答案
确保 Angular 模型(数量)也具有正确的值。
<?php
function qtyList($selectName, $selectQty)
{
$str = '<select ng-init="qty =\'' . $selectQty . '\'" ng-model="qty">';
for ($i = 1; $i <= 100; $i++) {
$str .= '<option value="' . $i . '">' . $i . '</option>';
}
$str .= '</select>';
return $str;
}
echo qtyList('testName', "5");
关于javascript - AngularJs Select通过PHP生成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45798648/