wex5笔记(view:2383)

1.获取表单输入

  1. var input1 = this.comp('input1').val(); // input1为xid

2.bind-visible动态显示
UI中

  1. bind-visible="isBoxShow"

js中

  1. var Model = function(){
  2. this.isBoxShow = justep.Bind.observable(false);
  3. };
  4. Model.prototype.showBox = function(event){
  5. this.isBoxShow.set(true);
  6. };

3.页面内的数据共享
页面加载时候ajax获取到数据,提交表单时候需要用到,直接在define下定义变量

4.提示框

  1. justep.Util.hint("操作成功");
  2. justep.Util.hint('test', {
  3. "type" : "info",
  4. "delay" : 1000000,
  5. "position" : "middle",
  6. "style" : "background-image : -webkit-linear-gradient(top, #EF0A69 0, #EF0A69 100%);"//只需要把 #EF0A69 改成其他颜色即可
  7. });

相关样式

  1. .x-hint{
  2. font-size:28px;
  3. color:blue;
  4. }

5.获取jquery对象

  1. $(this.getElementByXid('modalBox')).show();

6.img标签

  1. <img src="" alt="" xid="image1" bind-attr-src="$model.toUrl('./img/weixin.png')" style="width:40px;height:40px;"></img>
  1. //图片路径转换
  2. Model.prototype.toUrl = function(url){
  3. return url ? require.toUrl(url) : "";
  4. };

7.页面中读取data中的数据

  1. <label class="x-label" xid="label1" bind-text='$model.regData.label("userName")'/> // 获取‘regData’data组件中'显示名称'部分的值

8.渲染列表
class="x-list-template"下的第一个节点为模板,其所有子节点根据数据进行循环

  1. <div component="$UI/system/components/justep/list/list" data="settlementListData">
  2. <div class="x-list-template">
  3. <span bind-text="ref('id')"></span>
  4. </div>
  5. </div>

list组件的data属性和data组件xid的对应

  1. <div component="$UI/system/components/justep/data/data" autoLoad="true" xid="settlementListData" idColumn="id" onCustomRefresh="getSettlementList">
  2. <column label="id" name="id" type="String" xid="xid3"></column>
  3. </div>

js部分

  1. Model.prototype.getSettlementList = function(event){
  2. var me = this;
  3. var url = 'Merchantapi/SortingApi/getSettlementList';
  4. var memberToken = localStorage.memberToken;
  5. var parameter = {
  6. memberToken: memberToken,
  7. status: 1
  8. };
  9. me.comp("settlementListData").clear();
  10. ajax(url, 'post', parameter, function(res){
  11. console.log(res);
  12. if (res.apiCode == 0) {
  13. me.comp("settlementListData").newData({
  14. defaultValues : [{
  15. "id" :1,
  16. "name" :666
  17. }]
  18. });
  19. };
  20. });
  21. };

数据流向:js部分通过data组件的xid来操作dada组件的数据,list组件的data属性绑定data组件的xid属性
整个过程中,data组件的xid作为中转标识

9.嵌套列表
创建两个data组件,分别对应两个list组件

  1. <div component="$UI/system/components/justep/data/data" autoload="true" xid="firstLocation" idcolumn="lid">
  2. <column label="lid" name="lid" type="String" xid="xid20"></column>
  3. <column label="name" name="name" type="String" xid="xid21"></column>
  4. <data xid="default1">
  5. [{&quot;lid&quot;:&quot;1&quot;,&quot;name&quot;:&quot;0&quot;}]
  6. </data>
  7. </div>
  8. <div component="$UI/system/components/justep/data/data" autoload="true" xid="secondLocation" idcolumn="lid">
  9. <column label="lid" name="lid" type="String" xid="xid22"></column>
  10. <column label="parentId" name="parentId" type="String" xid="xid23"></column>
  11. <column label="name" name="name" type="String" xid="xid24"></column>
  12. </div>

html部分,用到dataitemalias属性和filter

  1. <div component="$UI/system/components/justep/list/list" data="firstLocation" dataitemalias="firstRow">
  2. <div class="x-list-template">
  3. <div class="firstItem">
  4. <span bind-text="ref('name')"></span>
  5. <div component="$UI/system/components/justep/list/list" data="secondLocation" filter="$row.val('parentId')==firstRow.val('lid')">
  6. <div class="x-list-template">
  7. <span bind-text="ref('name')"></span>
  8. </div>
  9. </div>
  10. </div>
  11. </div>
  12. </div>

数据结构,子列表parentId和父列表lid对应

  1. {
  2. "location": [{
  3. "lid": "1",
  4. "name": "\u8d27\u4f4dA",
  5. "secondLocation": [{
  6. "lid": "2",
  7. "parentId": "1",
  8. "name": "A1"
  9. },
  10. {
  11. "lid": "3",
  12. "parentId": "1",
  13. "name": "A2"
  14. },
  15. {
  16. "lid": "4",
  17. "parentId": "1",
  18. "name": "A3"
  19. },
  20. {
  21. "lid": "5",
  22. "parentId": "1",
  23. "name": "A4"
  24. }]
  25. },
  26. {
  27. "lid": "8",
  28. "name": "\u8d27\u4f4dB",
  29. "secondLocation": [{
  30. "lid": "9",
  31. "parentId": "8",
  32. "name": "B1"
  33. },
  34. {
  35. "lid": "10",
  36. "parentId": "8",
  37. "name": "B2"
  38. },
  39. {
  40. "lid": "11",
  41. "parentId": "8",
  42. "name": "B3"
  43. }]
  44. }]
  45. }

js部分,注意外层循环开始时候调用clear对列表进行清除

  1. me.comp("firstLocation").clear();
  2. me.comp("secondLocation").clear();
  3. for (var i = 0; i < locationData.length; i++) {
  4. me.comp("firstLocation").newData({
  5. defaultValues: [{
  6. "lid": locationData[i].lid,
  7. "name": locationData[i].name
  8. }]
  9.  
  10. });
  11. var secondlocationData = locationData[i].secondLocation;
  12. for (var j = 0; j < secondlocationData.length; j++) {
  13. me.comp("secondLocation").newData({
  14. defaultValues: [{
  15. "lid": secondlocationData[j].lid,
  16. "name": secondlocationData[j].name,
  17. "parentId": secondlocationData[j].parentId
  18. }]
  19.  
  20. });
  21. }
  22.  
  23. //second
  24. }

10.页面传参

12.data组件相关
data单个对象赋值

  1. me.comp('count').setValue('countYes',res.countYes);
  2. me.comp('count').setValue('countNo',res.countNo);

data数组赋值

  1. me.comp("list").clear();
  2. for (var i = 0; i < data.length; i++) {
  3. me.comp("list").newData({
  4. defaultValues: [{
  5. "id": data[i].id,
  6. "time": data[i].updatetime,
  7. "settlementNo": data[i].settlementNo,
  8. "settlement": data[i].settlement
  9. }]
  10. });
  11. }

直接从data取值

  1. <span bind-text=' $model.count.val("countNo")'></span>

http://blog.sina.com.cn/s/blog_667ac0360102wl8h.html

13.什么时候需要data组件