Sencha touch 中的数据视图

发布于 2024-10-29 02:11:00 字数 2868 浏览 2 评论 0原文

我是 sench-touch 的新手。我正在尝试使用数据存储显示 JSON 数据。

这是我的代码“gridView2.js”代码:

Ext.setup({
    tabletStartupScreen: 'tablet_startup.png',
    phoneStartupScreen: 'phone_startup.png',
    icon: 'icon.png',
    glossOnIcon: false,

   onReady: function() {        

        Ext.regModel('Product', {
            fields: [
                {name: 'name',        type: 'string'},
                {name: 'description', type: 'string'},
                {name: 'price',       type: 'float'},
                {name: 'image_url',   type: 'string'},
                {name: 'in_stock',    type: 'boolean'}
            ]
        });

        Ext.regModel('car', {
            fields: [                               
                {name: 'manufacture',type: 'string'},
                {name: 'model',   type: 'string'},
                {name: 'price',    type: 'decimal'}

            ]
        });

        var productsList = new Ext.DataView({
            store: new Ext.data.Store({
                model: 'car',
                proxy: {
                    type: 'ajax',
                    url : 'cars.json',
                    reader: {
                        type: 'json',
                        root: 'data'
                    }
                }
            }),
            tpl: new Ext.XTemplate(
                '<tpl for=".">',
                    '<div>',
                        '<img src="{manufacture}" />',
                        '<div class="button">Buy</div>',
                    '</div>',
                '</tpl>'
            ),
            fullscreen: true,
            autoLoad : true
        });


    }//ends onReady   
});

我的 JSON 文件包含:

{"data":[{"created_at":null,"id":1,"manufacture":"tata","model":"indica","price":200000,"updated_at":null},{"created_at":null,"id":2,"manufacture":"suzuki","model":"waganor","price":400000,"updated_at":null},{"created_at":null,"id":3,"manufacture":"mahindra","model":"xylo","price":600000,"updated_at":null}],"results":3}

我的 html 代码是:

登录屏幕 2

 <!-- Sencha Touch CSS -->
 <link rel="stylesheet" href="resources/css/sencha-touch.css" type="text/css">

 <!-- Custom CSS -->
  <!--<link rel="stylesheet" href="css/guide.css" type="text/css">-->


 <!-- Sencha Touch JS -->
 <script type="text/javascript" src="sencha-touch-debug.js"></script>
<script type="text/javascript" src="sencha-touch.js"></script>

 <!-- Application JS -->
 <!--  <script type="text/javascript" src="transaction.js"></script> -->
  <script type="text/javascript" src="gridView2.js"></script> 

我的问题是当我执行 html 文件时它什么也不显示。

I am new in sench-touch. I am trying to show JSON data using data Store.

Here is my code "gridView2.js" code:

Ext.setup({
    tabletStartupScreen: 'tablet_startup.png',
    phoneStartupScreen: 'phone_startup.png',
    icon: 'icon.png',
    glossOnIcon: false,

   onReady: function() {        

        Ext.regModel('Product', {
            fields: [
                {name: 'name',        type: 'string'},
                {name: 'description', type: 'string'},
                {name: 'price',       type: 'float'},
                {name: 'image_url',   type: 'string'},
                {name: 'in_stock',    type: 'boolean'}
            ]
        });

        Ext.regModel('car', {
            fields: [                               
                {name: 'manufacture',type: 'string'},
                {name: 'model',   type: 'string'},
                {name: 'price',    type: 'decimal'}

            ]
        });

        var productsList = new Ext.DataView({
            store: new Ext.data.Store({
                model: 'car',
                proxy: {
                    type: 'ajax',
                    url : 'cars.json',
                    reader: {
                        type: 'json',
                        root: 'data'
                    }
                }
            }),
            tpl: new Ext.XTemplate(
                '<tpl for=".">',
                    '<div>',
                        '<img src="{manufacture}" />',
                        '<div class="button">Buy</div>',
                    '</div>',
                '</tpl>'
            ),
            fullscreen: true,
            autoLoad : true
        });


    }//ends onReady   
});

my JSON file contains:

{"data":[{"created_at":null,"id":1,"manufacture":"tata","model":"indica","price":200000,"updated_at":null},{"created_at":null,"id":2,"manufacture":"suzuki","model":"waganor","price":400000,"updated_at":null},{"created_at":null,"id":3,"manufacture":"mahindra","model":"xylo","price":600000,"updated_at":null}],"results":3}

my html code is:

Login Screen 2

 <!-- Sencha Touch CSS -->
 <link rel="stylesheet" href="resources/css/sencha-touch.css" type="text/css">

 <!-- Custom CSS -->
  <!--<link rel="stylesheet" href="css/guide.css" type="text/css">-->


 <!-- Sencha Touch JS -->
 <script type="text/javascript" src="sencha-touch-debug.js"></script>
<script type="text/javascript" src="sencha-touch.js"></script>

 <!-- Application JS -->
 <!--  <script type="text/javascript" src="transaction.js"></script> -->
  <script type="text/javascript" src="gridView2.js"></script> 

My prblem is when I am executing html file it shows nothing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丶情人眼里出诗心の 2024-11-05 02:11:00

以下代码是正确且有效的:

Ext.setup({
    tabletStartupScreen: 'tablet_startup.png',
    phoneStartupScreen: 'phone_startup.png',
    icon: 'icon.png',
    glossOnIcon: false,

   onReady: function() {        

        Ext.regModel('Product', {
            fields: [
                {name: 'name',        type: 'string'},
                {name: 'description', type: 'string'},
                {name: 'price',       type: 'float'},
                {name: 'image_url',   type: 'string'},
                {name: 'in_stock',    type: 'boolean'}
            ]
        });

        Ext.regModel('car', {
            fields: [                               
                {name: 'manufacture',type: 'string'},
                {name: 'model',   type: 'string'},
                {name: 'price',    type: 'decimal'}

            ]
        });

        var productsList = new Ext.DataView({
            store: new Ext.data.Store({
                model: 'car',
                proxy: {
                    type: 'ajax',
                    url : 'cars.json',
                    reader: {
                        type: 'json',
                        root: 'data'
                    }
                },
                autoLoad : true
            }),
            tpl: new Ext.XTemplate(
                '<tpl for=".">',
                    '<div class="item">',
                        '<img src="{manufacture}" />',
                        '<div class="button">Buy</div>',
                    '</div>',
                '</tpl>'
            ),
            itemSelector: "div.item",
            fullscreen: true

        });
   }
});

您忘记为 DataView 添加 itemSelector 并将 auroLoad 属性置于商店定义之外

Following code is correct and working:

Ext.setup({
    tabletStartupScreen: 'tablet_startup.png',
    phoneStartupScreen: 'phone_startup.png',
    icon: 'icon.png',
    glossOnIcon: false,

   onReady: function() {        

        Ext.regModel('Product', {
            fields: [
                {name: 'name',        type: 'string'},
                {name: 'description', type: 'string'},
                {name: 'price',       type: 'float'},
                {name: 'image_url',   type: 'string'},
                {name: 'in_stock',    type: 'boolean'}
            ]
        });

        Ext.regModel('car', {
            fields: [                               
                {name: 'manufacture',type: 'string'},
                {name: 'model',   type: 'string'},
                {name: 'price',    type: 'decimal'}

            ]
        });

        var productsList = new Ext.DataView({
            store: new Ext.data.Store({
                model: 'car',
                proxy: {
                    type: 'ajax',
                    url : 'cars.json',
                    reader: {
                        type: 'json',
                        root: 'data'
                    }
                },
                autoLoad : true
            }),
            tpl: new Ext.XTemplate(
                '<tpl for=".">',
                    '<div class="item">',
                        '<img src="{manufacture}" />',
                        '<div class="button">Buy</div>',
                    '</div>',
                '</tpl>'
            ),
            itemSelector: "div.item",
            fullscreen: true

        });
   }
});

You forgot to add itemSelector for DataView and put auroLoad property out of store definition

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文