Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.36新特性:ms-duplex 尝试保持原有数据的类型 #520

Closed
RubyLouvre opened this issue Oct 12, 2014 · 8 comments
Closed

1.36新特性:ms-duplex 尝试保持原有数据的类型 #520

RubyLouvre opened this issue Oct 12, 2014 · 8 comments

Comments

@RubyLouvre
Copy link
Owner

<!DOCTYPE html>
<html>
    <head>
        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width">
        <script src="avalon.js" type="text/javascript"></script>
        <script>
            var vmodel = avalon.define("test", function(vm) {
                vm.aaa = 222
                vm.bbb = 111
                vm.ccc = false
                vm.$watch("aaa", function(a) {
                    console.log(a)
                })
                vm.$watch("bbb", function(a) {
                    console.log(a)
                })
                vm.$watch("ccc", function(a) {
                    console.log( a)
                })
            })

        </script>

    </head>
    <body ms-controller="test">
        <input ms-duplex="aaa"/>{{aaa}}
        <select ms-duplex="bbb">
            <option>
                111
            </option>
            <option>
                222
            </option>
            <option>
                333
            </option>
            <option>
                444
            </option>
        </select>
        <select ms-duplex="ccc">
            <option>
                true
            </option>
            <option>
                false
            </option>
        </select>
        <button ms-click="add" type="button">add</button>
    </body>
</html>
@xw332
Copy link

xw332 commented Oct 13, 2014

之前的一次更新“优化 ms-duplex,对于 checkbox,现在不强制对应一个数组,交由内部转换”
不明白实际对应什么例子,下面的demo没有效果,也没有错误提示

<!DOCTYPE HTML>
<html>
  <head>
    <meta charset="UTF-8">
    <title>测试用例</title>
  </head>
  <body ms-controller="xxx">
    <div>
      <input type="checkbox" ms-duplex="x" value="2">x:{{x}}
      <input type="checkbox" ms-duplex-radio="x">x:{{x}}
    </div>

    <script src="avalon.js"></script>
    <script>
      var model = avalon.define({
        $id: 'xxx',
        x: 2
      });
    </script>
  </body>
</html>

@RubyLouvre
Copy link
Owner Author

之前的版本,还没有对checkbox进行类型转换,现在好了

<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="UTF-8">
        <title>测试用例</title>
        <script src="avalon.js"></script>
    </head>
    <body ms-controller="test">
        <div>
            <input type="checkbox" ms-duplex="x" value="2">2
            <input type="checkbox" ms-duplex="x" value="4">4
            <button type="button" ms-click="change">
                将x改成{{ x == 2 ? 4: 2}}
            </button>

            <input type="checkbox" ms-duplex-radio="x">x:{{x}}
        </div>
        <script>
var model = avalon.define({
    $id: 'test',
    x: 2,
    change: function() {
        model.x = model.x === 2 ? 4 : 2
    }
});
model.$watch("x", function(a) {
    console.log(a)
})
        </script>
    </body>
</html>

@RubyLouvre
Copy link
Owner Author

adf5d4c

@xw332
Copy link

xw332 commented Oct 13, 2014

上面的demo好像没有双向的概念在里面,只是验证了数据源变化,视图会跟着变化,但是点击切换checkbox没什么效果 @RubyLouvre

@RubyLouvre
Copy link
Owner Author

有啊,你应该认真了解一下ms-duplex及其分支的各种用法

@xw332
Copy link

xw332 commented Oct 13, 2014

那这个对应的是原来那种写法?新的写法还不熟,可以说明一下

@RubyLouvre
Copy link
Owner Author

用法还是原来的啊
只是如果能数据转换,它就尝试数据转换,尝试数据转换的条件是非常苛刻严格的

@xw332
Copy link

xw332 commented Oct 13, 2014

你可以试试这个demo,新版本没看出来效果 @RubyLouvre

<!DOCTYPE HTML>
<html>
  <head>
    <meta charset="UTF-8">
    <title>测试用例</title>
  </head>
  <body ms-controller="xxx">
    <div>
      新版本:
      <input type="checkbox" ms-duplex="x" value="1">
      <input type="checkbox" ms-duplex="x" value="false">x:{{x}}
      <br>radio:
      <input type="checkbox" ms-duplex-radio="y">y:{{y}}
      <br>数组:
      <input type="checkbox" ms-duplex="z" value="1">
      <input type="checkbox" ms-duplex="z" value="false">z:{{z}}
    </div>

    <script src="avalon.mobile.js"></script>
    <script>
      var model = avalon.define({
        $id: 'xxx',
        x: 1,
        y: true,
        z: []
      });
    </script>
  </body>
</html>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants