首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Framework7中获取输入的数据?

如何在Framework7中获取输入的数据?
EN

Stack Overflow用户
提问于 2016-12-20 09:19:33
回答 1查看 1.4K关注 0票数 0

我在cordova中使用cordova,我的要求如下:

正如您所看到的,我希望从表单中存储我的inputs值:

在我的my-app.js

代码语言:javascript
复制
// Initialize your app
var myApp = new Framework7();

// Export selectors engine
var $$ = Dom7;

// Add views
var view1 = myApp.addView('#view-1');
var view2 = myApp.addView('#view-2', {
    // Because we use fixed-through navbar we can enable dynamic navbar
    dynamicNavbar: true
});
var view3 = myApp.addView('#view-3');
var view4 = myApp.addView('#view-4');


var ptrContent = $$('.pull-to-refresh-content');




$$('.save-storage-data').on('click', function() {
    var storedData = myApp.formStoreData('my-info-form', {
                                     'name': 'John', // this value should be the input's value, I just write for test here
                                     'address':'address',  // this value should be the input's value, I just write for test here
                                     'page':'page',  // this value should be the input's value, I just write for test here
                                     'tel':'139',  // this value should be the input's value, I just write for test here
                                     'email': 'john@doe.com',  // this value should be the input's value, I just write for test here
                                     'gender': 'female',  // this value should be the input's value, I just write for test here
                                     'isAcceptPushNotification': ['yes'],  // this value should be the input's value, I just write for test here
                                     'birthday': ''  // this value should be the input's value, I just write for test here
                                     });
    alert('success')
});

正如您所看到的,$$('.save-storage-data').on('click', function()函数是我想要的,我想将form信息保存到我的应用程序中。

另外,我应该判断是否所有的输入都充满了值,然后保存数据。

EN

回答 1

Stack Overflow用户

发布于 2016-12-21 05:36:42

让我们循环遍历所有表单输入字段,并在保存之前检查它们是否都已填充:

代码语言:javascript
复制
$$('.save-storage-data').on('click', function() {

    $$('.save-storage-data input').each(function(i, obj) {
        if (!$$(this).val()) {
           myApp.alert("Please fill all the required fields.");
           return false;
        }
    });

    var storedData = myApp.formStoreData('my-info-form', {
                                     'name': 'John', // this value should be the input's value, I just write for test here
                                     'address':'地址',  // this value should be the input's value, I just write for test here
                                     'page':'page',  // this value should be the input's value, I just write for test here
                                     'tel':'139',  // this value should be the input's value, I just write for test here
                                     'email': 'john@doe.com',  // this value should be the input's value, I just write for test here
                                     'gender': 'female',  // this value should be the input's value, I just write for test here
                                     'isAcceptPushNotification': ['yes'],  // this value should be the input's value, I just write for test here
                                     'birthday': ''  // this value should be the input's value, I just write for test here
                                     });
    alert('保存成功')
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41238674

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档