当前位置: 首页 > 工具软件 > Live Query > 使用案例 >

javascript livequery 实例

白泽语
2023-12-01

test.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="//cdn1.lncld.net/static/js/3.3.0/av-live-query-min.js"></script>
    <script type="text/javascript">

        function hello(){
            var APP_ID = '自己ID';
            var APP_KEY = '自己key';
            AV.init({
            appId: APP_ID,
            appKey: APP_KEY,
            });

            create();

        }


        //新增
        function create(){
            var testObj = new AV.Object('Todo');
            testObj.set('state','doing');
            testObj.save();
        }

    </script>
</head>
<body>
    <button onclick="hello()">hello</button>
</body>
</html>

tests.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <!-- 存储服务 -->
    <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="//cdn1.lncld.net/static/js/3.3.0/av-live-query-min.js"></script>
    <script type="text/javascript">

        $(document).ready(function(){
            var APP_ID = '';
            var APP_KEY = '';
            AV.init({
            appId: APP_ID,
            appKey: APP_KEY,
            });

            // 正在进行中的 Todo
            var doingQuery = new AV.Query('Todo').equalTo('state', 'doing');

            //订阅
            doingQuery.subscribe().then(function(liveQuery) {
             liveQuery.on('create', function(newDoingItem) {
                 console.log(123);
                 });    

        });


    </script>
</head>
<body>

</body>
</html>
 类似资料: