每个布局我们需要不同的事件吗?(Do we need different events for each layout?)
在_initializeLayout之前调用我的渲染方法:
var _initializeLayout = function() { console.log('initializeLayout...'); Controller.layout = new Layout(); Controller.layout.on("show", function() { vent.trigger("layout:rendered"); }); vent.trigger('app:show', Controller.layout); };
我在on rendering方法中使用布局:
// controller attach a sub view/ search View vent.on("layout:rendered", function() { console.log('layout:rendered =>StartController'); // render views for the existing HTML in the template, and attach it to the layout (i.e. don't double render) var inspectorStartView = new InspectorStartView(); Controller.layout.inspector.attachView(inspectorStartView); var playerStartView = new PlayerStartView(); Controller.layout.player.attachView(playerStartView); });
当我尝试它时,我的on渲染回调在_initializeLayout()之前被调用。 我在路由器/控制器方法中调用_initializeLayout:
Controller.go_inspector_control_center = function(term) { _initializeLayout(); //vent.trigger("search:term", term); };
我刚刚再次运行它,发现一个事件是从另一个控制器的_initializeLayout()方法触发的:
// private var _initializeLayout = function() { console.log('initialize Start Layout...'); Controller.layout = new Layout(); Controller.layout.on("show", function() { **vent.trigger("layout:rendered"); // <--** }); vent.trigger('app:show', Controller.layout); };
事件似乎需要具有唯一的名称。 我会试试的。 如果有人知道请进入。
安德鲁
My rendered method is being called before _initializeLayout:
var _initializeLayout = function() { console.log('initializeLayout...'); Controller.layout = new Layout(); Controller.layout.on("show", function() { vent.trigger("layout:rendered"); }); vent.trigger('app:show', Controller.layout); };
I use the layout in the on rendered method:
// controller attach a sub view/ search View vent.on("layout:rendered", function() { console.log('layout:rendered =>StartController'); // render views for the existing HTML in the template, and attach it to the layout (i.e. don't double render) var inspectorStartView = new InspectorStartView(); Controller.layout.inspector.attachView(inspectorStartView); var playerStartView = new PlayerStartView(); Controller.layout.player.attachView(playerStartView); });
When I try it, my on rendered callback is called before _initializeLayout(). I have it calling _initializeLayout in the router/controller method:
Controller.go_inspector_control_center = function(term) { _initializeLayout(); //vent.trigger("search:term", term); };
I just ran it again and found that an event was being triggered from a different controller's _initializeLayout() method:
// private var _initializeLayout = function() { console.log('initialize Start Layout...'); Controller.layout = new Layout(); Controller.layout.on("show", function() { **vent.trigger("layout:rendered"); // <--** }); vent.trigger('app:show', Controller.layout); };
It appears that the events need to have unique names. I'll try that. If anyone knows please chime in.
Andrew
原文:https://stackoverflow.com/questions/14651603
最满意答案
我这样做的方法是创建一个.sql文件并将其放在res / raw文件夹中。
此脚本包含
DROP IF EXISTS
语句以删除所有现有表,然后执行所有CREATE TABLE
语句。 如果您当然可以添加INSERT
语句。为了运行这个脚本,我在SQLOpenLiteHelper扩展类中编写了以下方法。 如果您的文件名为db_create.sql,则rawResourceId将为
R.raw.db_create
。/** * Runs the provided raw resource as a script that doesn't return anything. * * Warning: this is a NOT a foolproof SQL script interpreter. * * Please note: * All terminators (;) must be at the end of a line. * * * @param db * @param rawResourceId */ public void runScript(SQLiteDatabase db, int rawResourceId, boolean okToFail) { Log.i(getClass().getSimpleName(), "Running SQL script"); InputStream in = context.getResources().openRawResource(rawResourceId); Scanner s = new Scanner(in); String sql = ""; while (s.hasNext()) { sql += " " + s.nextLine(); if (sql.endsWith(";")) { try { db.execSQL(sql); } catch (SQLException e) { if (okToFail) Log.w(getClass().getSimpleName(), e.getMessage()); else throw e; } sql = ""; } } s.close(); }
The way I did this is create a .sql file and put it in the res/raw folder.
This script contains
DROP IF EXISTS
statements to drop all existing tables and then does all theCREATE TABLE
statements. If course you can addINSERT
statements as well.To run this script I wrote the following method in my SQLOpenLiteHelper extension class. Your rawResourceId will be
R.raw.db_create
, if your file is called db_create.sql./** * Runs the provided raw resource as a script that doesn't return anything. * * Warning: this is a NOT a foolproof SQL script interpreter. * * Please note: * All terminators (;) must be at the end of a line. * * * @param db * @param rawResourceId */ public void runScript(SQLiteDatabase db, int rawResourceId, boolean okToFail) { Log.i(getClass().getSimpleName(), "Running SQL script"); InputStream in = context.getResources().openRawResource(rawResourceId); Scanner s = new Scanner(in); String sql = ""; while (s.hasNext()) { sql += " " + s.nextLine(); if (sql.endsWith(";")) { try { db.execSQL(sql); } catch (SQLException e) { if (okToFail) Log.w(getClass().getSimpleName(), e.getMessage()); else throw e; } sql = ""; } } s.close(); }
相关问答
更多-
我这样做的方法是创建一个.sql文件并将其放在res / raw文件夹中。 此脚本包含DROP IF EXISTS语句以删除所有现有表,然后执行所有CREATE TABLE语句。 如果您当然可以添加INSERT语句。 为了运行这个脚本,我在SQLOpenLiteHelper扩展类中编写了以下方法。 如果您的文件名为db_create.sql,则rawResourceId将为R.raw.db_create 。 /** * Runs the provided raw resource as a script ...
-
你必须给出整个WHERE子句,也就是date = : ourDatabase.update(My_DAILYTABLE, cv, DATE+" = (select...)", null); You have to give the entire WHERE clause, that is, also the date =: ourDatabase.update(My_DAILYTABLE, cv, DATE+" = (select...)", null);
-
我认为问题在于: nRet = sqlite3_bind_blob (res, 1, &head, head.Size(), SQLITE_TRANSIENT); 您无法获取TASK_HEAD结构的地址并将其传递给sqlite。 要构建blob,您需要平面数据,没有指针和动态缓冲区,如std :: string对象。 您需要在绑定操作之前在缓冲区中序列化TASK_HEAD结构。 例如: struct TASK_HEAD { TASK_ID id; std::string userData ...
-
在SQLITE数据库中插入值(Insert Values In SQLITE Database)[2023-09-11]
//tyr this code // you must give the column name to insert values in DB NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES); NSString *documentsDir = [paths objectAtIndex:0]; ... -
如何在Android Studio上查看Sqlite数据库中插入的数据(How to view inserted data in Sqlite database on Android Studio)[2022-09-15]
如果您想在Log显示数据,请尝试以下代码: for (Contact cn : contacts) { String log = "Id: "+cn.getID()+" ,Name: " + cn.getName() + " ,Phone: " + cn.getPhoneNumber(); // Writing Contacts to log Log.d("Name: ", log); 其他显示database请参阅以下步骤: 转到T ... -
sqlite3不会自动存储更改日期,因此如果您想稍后获取更改日期,则应自行将日期插入数据库。 sqlite3 does not store change dates automatically, so if you want to get them later you should insert the date to database yourself.
-
既然您已经使用php标记了问题,那么您应该可以使用SQLite3 :: lastInsertRowID() 。 或者,纯SQLite解决方案是last_insert_rowid()函数。 Since you've tagged the question with php, you should be able to use SQLite3::lastInsertRowID(). Alternatively, a pure SQLite solution is the last_insert_rowid() ...
-
第二次返回0,因为事务被回滚,然后没有插入行。 你应该使用这种模式。 db.beginTransaction(); try { ... db.setTransactionSuccessful(); } finally { db.endTransaction(); } The second time returns 0 because the transaction is rolled back and then the rows are not ins ...
-
如何使用Sqlite for Android创建数据库文件(.sqlite)?(how to create database file(.sqlite) using Sqlite for Android?)[2022-06-06]
这可能是因为您的应用程序仍在使用旧数据库。 如果在创建之前检查现有数据库,那么您的应用程序将找到旧数据库并使用它。 但旧数据库没有您添加的新表。 您应该包括某种版本的数据库,并在创建数据库时检查它。 然后,如果现有数据库未达到最新版本,则可以覆盖它。 一个快速的解决方案是从手机/模拟器中完全卸载您的应用程序,然后重新安装/运行它,然后数据库将是最新的。 It is probably because your application is still working with the old database ... -
update方法只能更改表中已存在的行。 但是,应用程序永远不会在表中插入任何行。 创建数据库时应添加该行: public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + ...); db.execSQL("INSERT INTO " + DATABASE_TABLE + " DEFAULT VALUES"); } The update metho ...