小程序
小游戏
企业微信
微信支付
扫描小程序码分享
input输入框输入时,联想出搜索数据,点击搜索数据的某一项,把值填入输入框中,出现点击之后出现 联想出来的数据第二次弹出
1 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
点击后是否又请求了了联想的接口呢?
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
没有请求 又弹出来的时候数据跟之前是一样的
可以写个简单的代码片段么
<view class='input_container border_radius margin_top30 border'>
<text class='text' decode="{{true}}" space="{{true}}" style='color:{{color}}'>学校名称:</text>
<input placeholder="请输入学校名称" auto-focus type='text' name='schoolName' bindblur='bindSchoolNameBlur' bindinput='bindSchoolNameInput' value='{{schoolName}}' />
</view>
<view class="school_info school_position" style='background:{{color}};height:{{schoolBoxHeight}}rpx;' hidden='{{isShowSchool == false}}'>
<view wx:for="{{schoolList}}" wx:key="unique" hidden='{{isShowSchool == false}}' data-schoolname='{{item.schoolName}}' data-schoolid='{{item.schoolId}}' catchtap='switchSchoolName'>
<text>
{{item.cityName}} {{item.areaName}} {{item.schoolName}}</text>
bindSchoolNameInput: function(e) {
console.log(e);
var that = this;
params.url = "/user/school-list";
params.schoolName = e.detail.value;
app.request('/app-mini/port-forward', params).then(
res => {
if (res.ok) {
that.setData({
count: count + 1,
schoolList: res.schoolList,
isShowSchool: true,
schoolBoxHeight: res.schoolList.length > 5 ? 500 : res.schoolList.length * 100,
})
} else {
app.showToast(res.errorMsg);
}
);
},
switchSchoolName: function(e) {
this.onLoad(JSON.stringify({
schoolId: e.currentTarget.dataset.schoolid,
schoolName: e.currentTarget.dataset.schoolname,
type: 'school'
}))
onLoad: function(options) {
console.log(options);
if (JSON.stringify(options) != '{}') {
if (JSON.parse(options).type == 'school') {
this.setData({
schoolId: JSON.parse(options).schoolId,
schoolName: JSON.parse(options).schoolName,
isShowSchool: false
} else if (JSON.parse(options).type == 'student') {
studentName: JSON.parse(options).studentName,
studentId: JSON.parse(options).studentId,
phone: JSON.parse(options).phone,
isShowStudent: false
params.url = "/user/relationship-list";
params.stduentId = this.data.studentId
console.log(res);
relationshipList: res.relationshipList,
relationshipId: res.relationshipList[that.data.index].relationshipId
wx.setNavigationBarColor({
frontColor: '#ffffff',
backgroundColor: app.getDataFromStorage('themeColor'),
color: app.getDataFromStorage('themeColor'),
这是所有的代码
麻烦提供能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
点击后是否又请求了了联想的接口呢?
没有请求 又弹出来的时候数据跟之前是一样的
可以写个简单的代码片段么
<view class='input_container border_radius margin_top30 border'>
<text class='text' decode="{{true}}" space="{{true}}" style='color:{{color}}'>学校名称:</text>
<input placeholder="请输入学校名称" auto-focus type='text' name='schoolName' bindblur='bindSchoolNameBlur' bindinput='bindSchoolNameInput' value='{{schoolName}}' />
</view>
<view class="school_info school_position" style='background:{{color}};height:{{schoolBoxHeight}}rpx;' hidden='{{isShowSchool == false}}'>
<view wx:for="{{schoolList}}" wx:key="unique" hidden='{{isShowSchool == false}}' data-schoolname='{{item.schoolName}}' data-schoolid='{{item.schoolId}}' catchtap='switchSchoolName'>
<text>
{{item.cityName}} {{item.areaName}} {{item.schoolName}}</text>
</view>
</view>
bindSchoolNameInput: function(e) {
console.log(e);
var that = this;
params.url = "/user/school-list";
params.schoolName = e.detail.value;
app.request('/app-mini/port-forward', params).then(
res => {
if (res.ok) {
that.setData({
count: count + 1,
schoolList: res.schoolList,
isShowSchool: true,
schoolBoxHeight: res.schoolList.length > 5 ? 500 : res.schoolList.length * 100,
})
} else {
app.showToast(res.errorMsg);
}
}
);
},
switchSchoolName: function(e) {
this.onLoad(JSON.stringify({
schoolId: e.currentTarget.dataset.schoolid,
schoolName: e.currentTarget.dataset.schoolname,
type: 'school'
}))
},
onLoad: function(options) {
console.log(options);
if (JSON.stringify(options) != '{}') {
if (JSON.parse(options).type == 'school') {
this.setData({
schoolId: JSON.parse(options).schoolId,
schoolName: JSON.parse(options).schoolName,
isShowSchool: false
})
} else if (JSON.parse(options).type == 'student') {
this.setData({
studentName: JSON.parse(options).studentName,
studentId: JSON.parse(options).studentId,
phone: JSON.parse(options).phone,
isShowStudent: false
})
var that = this;
params.url = "/user/relationship-list";
params.stduentId = this.data.studentId
app.request('/app-mini/port-forward', params).then(
res => {
console.log(res);
if (res.ok) {
that.setData({
relationshipList: res.relationshipList,
relationshipId: res.relationshipList[that.data.index].relationshipId
})
} else {
app.showToast(res.errorMsg);
}
}
);
}
}
wx.setNavigationBarColor({
frontColor: '#ffffff',
backgroundColor: app.getDataFromStorage('themeColor'),
})
this.setData({
color: app.getDataFromStorage('themeColor'),
})
},
这是所有的代码
麻烦提供能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)