【发布时间】:2019-07-26 08:14:16
【问题描述】:
我正在学习 VueJS,但我无法围绕选择部分进行思考(在我的例子中,我使用了教程页面中的单选。
直到现在,我让“用户”填充唯一的搜索框,我的查询(位于 data.php 中)是这个:
case 'list':
$b = new book;
$req = "SELECT id, isbn, ddc, title FROM book WHERE 1=1 ";
if(strlen($search)>0) {
$req .= "AND isbn LIKE '%$search%' OR ddc LIKE '%$search%' ";
}
$req.= "ORDER BY title LIMIT 0,50";
$fields = array("id","isbn","ddc", "title");
$res = $c->StructList($req,$fields,"json");
echo $res;
break;
在 index.php 中呈现,这个视图:
Old rendition until now with only one search box - WORKING
现在,我尝试在搜索框前一步。
New version with a SELECT OPTION - NOT WORKING
我想不让一个搜索框和任何可以填写的内容(ISBN 或杜威十进制分类)看起来很愚蠢,但这是我为这次培训进行的个人培训。
我的示例中的这两种分类都来自我数据库的 2 个不同的其他表(ISBN_code 和 DDC_code)。
在我的 index.php 文件中,我遵循了 Vue.js 教程中的选择选项。
<select v-model="selected">
<option disabled value="">Choose</option>
<option>Through the ISBN</option>
<option>Through the Dewey Decimal Classification</option>
</select>
<span>Selected : {{ selected }}</span><br><br>
在我的 data.php 上,现在我写道:
$b = new book;
$req = "SELECT id, isbn, ddc, title FROM book WHERE 1=1 ";
if(strlen($search)>0) {
$req .= "AND {{selected}} LIKE '%$search%' ";
}
$req.= "ORDER BY title LIMIT 0,50";
$fields = array("id","isbn","ddc", "title");
$res = $c->StructList($req,$fields,"json");
echo $res;
=> 我写了一个 1=1 是为了避免即使搜索栏(下面一行)的条件不是全字段也无法使查询正常工作。
最后在 app.js 文件中,我写道:
var vm = new Vue({
el:"#app",
data:{
list:[],
search:"",
selected:''
},
mounted:function(){
this.GetList();
},
methods:{
GetListe:_.debounce(function(search = ""){
var scope = this;
$.ajax({
url:"data.php?case=list",
type:"POST",
data:{search},
success:function(res){
scope.list = JSON.parse(res);
},
error:function(){
}
});
},500),
},
});
我不明白如何让查询使用这种方法,用户必须先选择一个分类代码。
我应该修改我的查询还是 v-bind 一些东西?比如https://vuejs.org/v2/guide/forms.html?
谢谢大家
【问题讨论】: