首页 \ 问答 \ sencha touch 2:列出具有模型关联的人口(sencha touch 2: list population with associations in model)

sencha touch 2:列出具有模型关联的人口(sencha touch 2: list population with associations in model)

作为sencha-touch2的学习项目,我试图用来自https://www.hnsearch.com/api的数据填充商店

我创建了模型并存储如下,在检查器视图中,我可以看到数据已被接收并正确映射。

我无法弄清楚的问题是,如何显示一个sencha xtype:list元素与嵌套在json中的实际结果项(Model:SearchResultItem)。 我尝试了以下内容,它将为我提供一个列表,其中包含一个列表项,其中包含结果,但我希望每个搜索结果都有一个列表项。

楷模:

Ext.define('senchaHackerNews.model.Search', {
extend: 'Ext.data.Model',

config: {
    fields: [{
        name: 'hits',
        type: 'int'
    }],

    associations: {
        type: 'hasMany',
        name: 'results',
        model: 'senchaHackerNews.model.SearchResults',
        associationKey: 'results'
    }

}
});


Ext.define('senchaHackerNews.model.SearchResults', {
extend: 'Ext.data.Model',

config: {
    fields: [{
        name: 'score',
        type: 'float'
    }],

    associations: {
        type: 'hasOne',
        name: 'item',
        model: 'senchaHackerNews.model.SearchResultItem',
        associationKey: 'item'
    }
}
});


Ext.define('senchaHackerNews.model.SearchResultItem', {
extend: 'Ext.data.Model',

config: {
    fields: [{
        name: 'username',
        type: 'string'
    }, {
        name: 'title',
        type: 'string'
    }, {
        name: 'points',
        type: 'int'
    }, {
        name: 'url',
        type: 'string'
    }, {
        name: 'domain',
        type: 'string'
    }]

}
}); 

商店:

Ext.define('senchaHackerNews.store.Search', {
extend: 'Ext.data.Store',
requires: ['senchaHackerNews.model.Search'],

config: {
    storeId: 'hnSearchStore',
    model: 'senchaHackerNews.model.Search',
    autoload: false,

    proxy: {
        type: 'jsonp',
        // url: 'http://api.thriftdb.com/api.hnsearch.com/items/_search?q=ipad',
        reader: {
            type: 'json',
            rootProperty: ''
        },
        callbackKey: 'callback'
    }
}
});

视图:

Ext.define('senchaHackerNews.view.Search', {
    extend: 'Ext.navigation.View',
    alias: 'widget.hnSearch',
    xtype: 'hnSearch',

    requires: ['Ext.field.Search'],

    initialize: function() {
        var xtpl = new Ext.XTemplate('<tpl for="results">{item.username} ---- {item.title} | <br></tpl>');

        this.add([

        {
            xtype: 'container',
            title: 'Search HN',
            layout: 'vbox',
            items: [{
                xtype: 'searchfield',
                placeHolder: 'Search HN News (at least 3 chars)',
                listeners: {
                    scope: this,
                    clearicontap: this.onSearchClearIconTap,
                    keyup: this.onSearchKeyUp
                }
            }, {
                xtype: 'list',
                flex: 1,
                itemTpl: xtpl,
                store: 'hnSearchStore',
                emptyText: 'No Matching Items',
            }]
        }

        ]);

        this.callParent(arguments);
    },


    onSearchKeyUp: function(field) {

        if(field.getValue() != '' && field.getValue().length > 3) {
            var store = Ext.StoreMgr.get('hnSearchStore');

            store.setProxy({
                url: 'http://api.thriftdb.com/api.hnsearch.com/items/_search?q='+field.getValue() 
            });

            store.load();
        } else if(field.getValue() == '') {
            Ext.StoreMgr.get('hnSearchStore').removeAll();
        }
    },

    onSearchClearIconTap: function() {
        Ext.StoreMgr.get('hnSearchStore').removeAll();
    }
});

示例JSON位于http://api.thriftdb.com/api.hnsearch.com/items/_search?q=facebook&pretty_print=true


as a learning project for sencha-touch2 i'm trying to populate a store with data from https://www.hnsearch.com/api

i have created the model and store as follow and in the inspector view i can see that data is received and correctly mapped.

the problem i cannot figure out is, how to show a sencha xtype:list element with the actual result items nested in the json (Model: SearchResultItem). i tried the following, which will give me a list with ONE list item with the results in it, but i would like to have a list item for each search result.

models:

Ext.define('senchaHackerNews.model.Search', {
extend: 'Ext.data.Model',

config: {
    fields: [{
        name: 'hits',
        type: 'int'
    }],

    associations: {
        type: 'hasMany',
        name: 'results',
        model: 'senchaHackerNews.model.SearchResults',
        associationKey: 'results'
    }

}
});


Ext.define('senchaHackerNews.model.SearchResults', {
extend: 'Ext.data.Model',

config: {
    fields: [{
        name: 'score',
        type: 'float'
    }],

    associations: {
        type: 'hasOne',
        name: 'item',
        model: 'senchaHackerNews.model.SearchResultItem',
        associationKey: 'item'
    }
}
});


Ext.define('senchaHackerNews.model.SearchResultItem', {
extend: 'Ext.data.Model',

config: {
    fields: [{
        name: 'username',
        type: 'string'
    }, {
        name: 'title',
        type: 'string'
    }, {
        name: 'points',
        type: 'int'
    }, {
        name: 'url',
        type: 'string'
    }, {
        name: 'domain',
        type: 'string'
    }]

}
}); 

store:

Ext.define('senchaHackerNews.store.Search', {
extend: 'Ext.data.Store',
requires: ['senchaHackerNews.model.Search'],

config: {
    storeId: 'hnSearchStore',
    model: 'senchaHackerNews.model.Search',
    autoload: false,

    proxy: {
        type: 'jsonp',
        // url: 'http://api.thriftdb.com/api.hnsearch.com/items/_search?q=ipad',
        reader: {
            type: 'json',
            rootProperty: ''
        },
        callbackKey: 'callback'
    }
}
});

view:

Ext.define('senchaHackerNews.view.Search', {
    extend: 'Ext.navigation.View',
    alias: 'widget.hnSearch',
    xtype: 'hnSearch',

    requires: ['Ext.field.Search'],

    initialize: function() {
        var xtpl = new Ext.XTemplate('<tpl for="results">{item.username} ---- {item.title} | <br></tpl>');

        this.add([

        {
            xtype: 'container',
            title: 'Search HN',
            layout: 'vbox',
            items: [{
                xtype: 'searchfield',
                placeHolder: 'Search HN News (at least 3 chars)',
                listeners: {
                    scope: this,
                    clearicontap: this.onSearchClearIconTap,
                    keyup: this.onSearchKeyUp
                }
            }, {
                xtype: 'list',
                flex: 1,
                itemTpl: xtpl,
                store: 'hnSearchStore',
                emptyText: 'No Matching Items',
            }]
        }

        ]);

        this.callParent(arguments);
    },


    onSearchKeyUp: function(field) {

        if(field.getValue() != '' && field.getValue().length > 3) {
            var store = Ext.StoreMgr.get('hnSearchStore');

            store.setProxy({
                url: 'http://api.thriftdb.com/api.hnsearch.com/items/_search?q='+field.getValue() 
            });

            store.load();
        } else if(field.getValue() == '') {
            Ext.StoreMgr.get('hnSearchStore').removeAll();
        }
    },

    onSearchClearIconTap: function() {
        Ext.StoreMgr.get('hnSearchStore').removeAll();
    }
});

Example JSON is here http://api.thriftdb.com/api.hnsearch.com/items/_search?q=facebook&pretty_print=true


原文:https://stackoverflow.com/questions/15944441
更新时间:2023-09-09 07:09

最满意答案

细分实际上并不使用您的补丁数据。 曲面细分单元,即实际生成三角形(或线条)的管道部分,在抽象补丁上运行 。 如果您的TES指定抽象补丁是四边形,则曲面细分器将在单位四边形上执行曲面细分。

您拥有多少个补丁顶点与此过程完全无关。

TES有点像顶点着色器; 每个顶点调用一次。 但不是GL_PATCHES原语中的每个顶点。 它是曲面细分原语的每个顶点。 因此,如果您对四边形进行细分,并且您的外层为(4,4,4,4)且内层为(4,4),则将生成25个顶点。 TES将被多次调用(至少;对于相同的顶点可以多次调用它),并且将在抽象补丁中告知特定顶点的位置。

TES的工作是决定如何使用抽象补丁坐标和真实补丁顶点数据来生成渲染管道要使用的实际每顶点数据。 例如,如果您要创建Bezier补丁,则会有16个补丁顶点。 TES的工作是采用抽象补丁坐标并使用双三次贝塞尔插值将补丁上的16个位置插入到抽象补丁中的特定位置。 这成为输出位置。 可以类似地计算法线,纹理坐标和其他数据。


Tessellation doesn't actually use your patch data. The tessellation unit, the part of the pipeline that actually generates triangles (or lines), operates on an abstract patch. If your TES specifies that the abstract patch is a quad, then the tessellator will perform tessellation on a unit quad.

How many patch vertices you have is completely irrelevant to this process.

The TES is a bit like a vertex shader; it gets called once per vertex. But not per vertex in the GL_PATCHES primitive. It's once per-vertex of the tessellated primitive. So, if you tessellate a quad, and your outer levels are (4, 4, 4, 4) and the inner levels are (4, 4), that will generate 25 vertices. The TES will be called that many times (at least; it can be called multiple times for the same vertex), and it will be told where within the abstract patch that particular vertex is.

The job of the TES is to decide how to use the abstract patch coordinate and the real patch vertex data to generate the actual per-vertex data to be used by the rendering pipeline. For example, if you're creating a Bezier patch, you would have 16 patch vertices. The TES's job would be to take the abstract patch coordinate and use bicubic Bezier interpolation to interpolate the 16 positions on the patch to that particular location in the abstract patch. That becomes the output position. Normals, texture coordinates, and other data can be computed similarly.

相关问答

更多
  • 当使用quads基本模式时,只有gl_TessCoord的前两个组件具有含义。 第3个成分是0.0。 gl_TessCoord[0]和gl_TessCoord[1]提供标准化的2D坐标,类似于纹理的UV坐标。 这意味着您必须在曲面细分评估着色器中使用gl_TessCoord[1]而不是gl_TessCoord[2] : float x = gl_TessCoord[0] * (tposition[1].x - tposition[0].x) + tposition[0].x; float z = gl_Te ...
  • 细分实际上并不使用您的补丁数据。 曲面细分单元,即实际生成三角形(或线条)的管道部分,在抽象补丁上运行 。 如果您的TES指定抽象补丁是四边形,则曲面细分器将在单位四边形上执行曲面细分。 您拥有多少个补丁顶点与此过程完全无关。 TES有点像顶点着色器; 每个顶点调用一次。 但不是GL_PATCHES原语中的每个顶点。 它是曲面细分原语的每个顶点。 因此,如果您对四边形进行细分,并且您的外层为(4,4,4,4)且内层为(4,4),则将生成25个顶点。 TES将被多次调用(至少;对于相同的顶点可以多次调用它), ...
  • gl_TessCoord表示与所有原始拓扑相同的概念。 该向量是当前图元中的位置,最好不要将其视为x , y和z 。 由于它是相对于表面的,因此u , v和w (可选)更直观。 您可以随意调用坐标(例如xyz , rgb , stp或uvw ),请注意,但uvw是规范符号。 OpenGL 4.5(核心配置文件) - 11.2.2 Tessellation Primitive Generation - p。 392 由基元生成器生成的每个顶点在标准化参数空间中具有关联的(u,v,w)或(u,v)位置,参数值在 ...
  • 补丁只是一个没有真正内在结构的点的集合......你的TCS和TES是有意义的。 与GL_TRIANGLES (由3个顶点严格定义)不同, GL_PATCHES每个补丁没有预定义的顶点数。 您可以使用以下方法自行设置补丁中的顶点数: glPatchParameteri ​(GL_PATCH_VERTICES​​, N); // where N is some value less than GL_MAX_PATCH_VERTICES 然后,绘制的每个N many顶点定义一个新的补丁基元。 补丁实际上只是用 ...
  • 你的问题非常适合于trisurf-给定一组点,你需要建立一个连接网格的三元组。 对于您的问题,您可以使用: %inner circle points and radius N1=20; r1=1; %outer circle points and radius N2=30; r2=5; %inner cicle angles thC=linspace(0,2*pi*(1-1/N1),N1)'; %inner cicle points xyzC=[r1*sin(thC), zeros(N1,1),r1* ...
  • 我解决了这个问题。 错误在加载着色器的代码中。 glShaderSource(pShader[st], 1, (const GLchar**)sProgram, NULL); 我将1更改为char * array sProgram的大小 I solved the problem. The error is in the code of loading shader. glShaderSource(pShader[st], 1, (const GLchar**)sProgram, NULL); I cha ...
  • 找到了怎么做。 在域着色器中计算顶点位置后,可以进行修改。 :d Found out how to do it. Modifications can be made after the vertex position has been calculated in the domain shader. :D
  • 可以使用简单的递归找到单个三角形(内部和外部细分相等)的重心细分的三角形数量: // Calculate number of triangles produced by barycentric subdivision (i.e. tessellation) // Where n is the level of detail lod and outer and inner level is always equal int calculateTriangles(int n) { if(n < 0) ...
  • 您需要将四边形分成两个三角形(哪种方式无关紧要),计算两个法线并对其进行平均。 理想情况下,两个法线都是一样的,而在另一种情况下,你有一个最好的近似值。 原因是一个三角形必然是平面的(没有其他方式),但是对于一个四边形你没有这样的保证。 因此,您根本不可能知道存在单个法线。 平均两个子三角形的法线并不理想,但您还可以在中间有“折叠”的原始元素上做些什么。 You will need to split the quad into two triangles (does not matter which way ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。