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

ms-bind的代替方案 #196

Closed
RubyLouvre opened this issue Dec 13, 2013 · 1 comment
Closed

ms-bind的代替方案 #196

RubyLouvre opened this issue Dec 13, 2013 · 1 comment

Comments

@RubyLouvre
Copy link
Owner

原来的方案

<!doctype html>
<html >
    <head>
        <script src="avalon.js"></script>
        <script>
            var model = avalon.define("test", function(vm) {
                vm.aaa = 11111
                vm.callback = function(a) {
                    this.innerHTML = a
                }
            })
            setInterval(function() {
                model.aaa = new Date - 0
            }, 50)
        </script>
    </head>
    <body ms-controller="test">
        <div ms-bind="aaa:callback">TEXT</div>
    </body>
</html>

替换方案,使用$watch与ms-attr-id

<!doctype html>
<html >
    <head>
        <script src="avalon.js"></script>
        <script>
            var model = avalon.define("test", function(vm) {
                vm.aaa = 11111
                vm.$watch("aaa", function(e){
                    var el = document.getElementById("aaa")
                    if(el){
                        el.innerHTML = e
                    }
                })
            })
            setInterval(function() {
                model.aaa = new Date - 0
            }, 50)
        </script>
    </head>
    <body ms-controller="test">
        <div ms-attr-id="'aaa'">TEXT</div>
    </body>
</html>
@fwon
Copy link

fwon commented Dec 27, 2013

出于什么考虑呢?

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