首页 \ 问答 \ 使用图像创建模型类(creating a model class with an image)

使用图像创建模型类(creating a model class with an image)

有没有一种有效的方法将图像加载到模型类中? 模型是这样的:

#import <Foundation/Foundation.h>
@interface ProjectData : NSObject {

NSString *titleText;
UIImage *photo;
NSString *descriptionText;

}

@property (nonatomic,retain) NSString *titleText;
@property (nonatomic,retain) UIImage *photo;
@property (nonatomic,retain) NSString *descriptionText;
@end

项目类似于目录。

我一直在使用mySQL数据库中的XML从webserver加载字符串。 图像在数据库中。 不太确定如何继续将图像加载到ProjectData类中。 NSMutableData? 或者有更简单的方法吗?

谢谢。


Is there an efficient way to load an image into a model class? The model is something like this:

#import <Foundation/Foundation.h>
@interface ProjectData : NSObject {

NSString *titleText;
UIImage *photo;
NSString *descriptionText;

}

@property (nonatomic,retain) NSString *titleText;
@property (nonatomic,retain) UIImage *photo;
@property (nonatomic,retain) NSString *descriptionText;
@end

Project is something like a catalog.

I have been loading the strings from webserver using XML from mySQL database. Images are on database. Not quite sure how to proceed with image loading into ProjectData class. NSMutableData? or is there an easier way?

Thanks.


原文:https://stackoverflow.com/questions/4904460
更新时间:2022-08-19 18:08

最满意答案

如果你的商店每个都有少于300条记录,并且页面上没有真正“那么多”商店,你应该做的是立即从php返回所有内容(或者更好的是加载所有商店的页面加载本身,但听起来你不能这样做)。 因此,不是你的一个ajax调用获取组合框中所选项的值,而是更像这样:

为每个商店定义了您的模型:

Ext.define("MyModel1", {
    extend: "Ext.data.Model",
    fields: [
        {name:"field_code", type:"string"},
        {name:"field_value",      type:"string"}
    ]
});

然后以非常简单的方式定义每个商店,注意我遗漏了您当前可能包含的阅读器和代理,为了提高性能,使用Ext.data.ArrayStore,因为它消除了记录中每个项目的必要性有一个命名属性(这会减少从服务器返回的文本以及前端的解析时间):

var myStore = Ext.create("Ext.data.ArrayStore", {
    model: "MyModel1",
    data:  []
});

现在,在您已定义的ajax请求中,将来自php的响应添加到存储中的所有数据作为返回的json对象中的属性,并将它们作为数组数组执行,确保元素顺序与您定义Ext.data的方式相匹配。模型。 我的示例的返回对象看起来像这样(数据是数组数组):

{
    my_combobox_value1: "CAD",
    my_combobox_data1: [
        ["CAD","Somthing for display of this record"],
        ["AN","Another Entry]
    ]
}

然后将ajax请求更改为如下所示:

Ext.Ajax.request({
    url: 'url/to/another/PHP/file/',
    scope: this,
    method: 'GET',
    params: {
        code_id: 'myUser',
        number: '12345'
    },

    success: function (response, opts) {
         var result = Ext.decode(response.responseText);
         myStore.loadData(result.my_combobox_data1);
         Ext.getCmp('nameId').setValue(result.my_combobox_value1);
         ... and rinse and repeat for all stores, make sure you set the value for each combobox after the store has been loaded :)
    },

});

这将为您提供最佳性能。 如果这不起作用,则必须使用具有处理服务器端所有内容的代理的存储,并根据需要加载数据。


If your stores each has less than about 300 records, and there aren't really 'that' many stores on your page, what you should do is return everything from the php at once (or more preferably load all the stores with the page load itself, but it sounds like you can't do that). So, instead of your one ajax call getting the values of the selected item in the combobox, think of it more like this:

Defined your models for each of the stores:

Ext.define("MyModel1", {
    extend: "Ext.data.Model",
    fields: [
        {name:"field_code", type:"string"},
        {name:"field_value",      type:"string"}
    ]
});

Then define each of your stores in a very simple manner, notice that I left out the reader and proxy that you are probably currently including, for improved performance, use Ext.data.ArrayStore because it removes the necessity for each item in a record to have a named attribute (this reduces the text returned from the server and also the parsing time on the frontend):

var myStore = Ext.create("Ext.data.ArrayStore", {
    model: "MyModel1",
    data:  []
});

Now in the ajax request that you already defined, add in the response from php all the data for the stores as attributes in the json object returned, and do them as array arrays making sure the element order matches how you defined the Ext.data.Model. The return object for my example would look something like this (the data is the array array):

{
    my_combobox_value1: "CAD",
    my_combobox_data1: [
        ["CAD","Somthing for display of this record"],
        ["AN","Another Entry]
    ]
}

Then change the ajax request to look something like this:

Ext.Ajax.request({
    url: 'url/to/another/PHP/file/',
    scope: this,
    method: 'GET',
    params: {
        code_id: 'myUser',
        number: '12345'
    },

    success: function (response, opts) {
         var result = Ext.decode(response.responseText);
         myStore.loadData(result.my_combobox_data1);
         Ext.getCmp('nameId').setValue(result.my_combobox_value1);
         ... and rinse and repeat for all stores, make sure you set the value for each combobox after the store has been loaded :)
    },

});

This will give you the best possible performance for you situation. If this does not work, you will have to use stores with proxies that handle everything on the server side and load data as needed.

相关问答

更多
  • 据我所知,没有办法在Umbraco节点上延迟加载标签。 至少那个没有作为功能提供。 我们经常遇到类似的节点/页面问题(很多富文本编辑器,每个都加载TinyMCE),而我们的方法是将这些内容拉出到子节点中。 这样,我的意思是主页面内容保留在页面节点中,但是您可以创建作为内容节点的子节点创建的新文档类型。 然后,您可以使用XSLT / Razor将存储在这些子节点中的内容提取到主内容页面上。 通过这样做,你仍然拥有页面上的所有内容,但它将被分成多个节点,每个节点都可以快速加载。 As far as I'm aw ...
  • 一些背景 我看了一下你的项目Dimitris。 我为“类创建”页面定义了加载创建时间(OS X 10.9上的Java 8 b129,2012 Macbook Air)。 我花了一秒多。 为了简化测试,我删除了使用并发服务加载新FXML的部分,并且在请求时直接在JavaFX应用程序线程上加载FXML - 它以这种方式工作更容易。 对不起,这里有很长的答案。 像这样的东西通常不适合进入StackOverflow,它们最终以教程或博客形式出现,但我很好奇发生了什么,所以我想我会花一些时间来研究它并写出它向上。 不 ...
  • 如果我正确理解您的问题,您要做的是从后续选择框中删除选项,具体取决于前几年选择框中选择的内容。 您不应该提交任何表单来执行此操作 - 您应该能够纯粹在javascript中执行此操作。 此代码应该有助于您入门: