收藏
回答

bindinput问题求解

input输入框输入时,联想出搜索数据,点击搜索数据的某一项,把值填入输入框中,出现点击之后出现 联想出来的数据第二次弹出

最后一次编辑于  05-30
回答关注问题邀请回答
收藏

1 个回答

  • 仙森ღ₅₂₀¹³¹⁴
    仙森ღ₅₂₀¹³¹⁴
    05-30

    点击后是否又请求了了联想的接口呢?

    05-30
    赞同
    回复 26
    • 李志宏
      李志宏
      05-30

      没有请求  又弹出来的时候数据跟之前是一样的

      05-30
      回复
    • 仙森ღ₅₂₀¹³¹⁴
      仙森ღ₅₂₀¹³¹⁴
      05-30

      可以写个简单的代码片段么

      05-30
      回复
    • 李志宏
      李志宏
      05-30回复仙森ღ₅₂₀¹³¹⁴

      <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'),

      })

      },


      05-30
      回复
    • 李志宏
      李志宏
      05-30回复仙森ღ₅₂₀¹³¹⁴

      这是所有的代码




      05-30
      回复
    • 仙森ღ₅₂₀¹³¹⁴
      仙森ღ₅₂₀¹³¹⁴
      05-30回复李志宏

      麻烦提供能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

      05-30
      回复
    查看更多(21)